0
나는 다음과 같은 XML이 : 나는 XML (C#을)에 LINQ를 사용하고 싶으면 무엇Linq에 XML에 Where 절
<root>
<property>
<propertydetails>
<siteid>4</siteid>
</propertydetails>
<gallery>
<image>
<imagesrc></imagesrc>
</image>
</gallery>
</property>
</root>
궁극적으로 특정 siteid에 대한 모든 갤러리의 이미지를 얻을됩니다. 그래서, 그것은 속성 값 요소/siteid가 특정 값과 같은 전체 속성 요소를 반환하는 것이 가장 좋을 것이라고 추측합니다.
나는 자손 내에서 요소를 검색하려고하는데 다음 요소가 직접 요소가 아니기 때문에 다음 코드가 작동하지 않는다고 생각합니다. siteid는 propertydetails 아래에 있지만 전체 속성 태그에 액세스하여 갤러리 이미지를 가져오고 싶습니다.
var properties = from property in root.Descendants("property")
where (int)property.Element("siteid") == id
select new PropertyModel
{
SiteId = Convert.ToInt32(property.Element("siteid").Value),
Images = new List<string>(from gallery in property.Descendants("gallery")
select gallery.Element("imagesrc").Value)
};
}