Reputation: 2249
Let's say that I've got this xml:
<items>
<item name="thumb">
<downloadStream>test1</downloadStream>
<downloadStream>test2</downloadStream>
<downloadStream>test3</downloadStream>
</item>
<item name="photo">
<downloadStream>test5</downloadStream>
<downloadStream>test6</downloadStream>
<downloadStream>test7</downloadStream>
</item>
</items>
I'm trying to write a LINQ to XML statement that returns me:
{"test5", "test6", "test7"}
In other words, it returns me the inner xml for each "downloadStream" node where the parent node has an attribute of (name="photo").
How do I do this?
Upvotes: 3
Views: 4848
Reputation: 13872
Something like this:
var rootElement = XElement.Parse(xml);
var results = rootElement.
.Elements()
.Where( e => e.Attribute("name") == "photo" )
.SelectMany( e => e.Elements )
.Select( e => e.Value );
Upvotes: 8