Conditional Element Selection in Linq to XML

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Im trying to pull data from an XML file via Linq by checking the attributes of the elements in the XML file. My linq query is working well, except for one requirement. In the XML sample below, I want to return all elements where the fruitatt =
"fruit", unless there is another element with a fruitatt="oranges". In that case I want to return all the "oranges" elements and none of the "fruit". Does that make sense? Is this possible? Im omitting a number of other elements
that I also check for, but those do have this requirement.
<content fruitatt="fruit <br/>
data for fruit<br/>
</content><br/>
<content fruitatt="oranges <br/>
data for oranges <br/>
</content>

View the full article
 
Back
Top