开发者

Query for not getting Child element using Linq-XML?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜