I have xml file like this.
<School Include="Y">
<Element ID="1" Name="ONE"/>
<Element ID="2" Name="TWO"/>
<Element ID="3" Name="THREE"/>
<Child1 Include="N">
<Element ID="4" Name="FOUR"/>
</Child1>
<Element ID="5" Name="FIVE"/>
</School>
I have to write query to get as:
<Element ID="1" Name="ONE"/>
<Element ID="2" Name="TWO"/>
<Element ID="3" Name="THREE"/>
<Element ID="5" N开发者_JAVA技巧ame="FIVE"/>
How to write Linq to XML query for getting above output?
var nodes = xdoc.Root.Elements("Element");
Assuming "Test.xml" is your file.
var document = XElement.Load("Test.xml");//Specify your file path
var elements = document.Decendants("Element");
foreach(var element in elements)
{
}
Thanks Ashwani
精彩评论