How to sort Node which are child using Attribute in xml



I have xml like



<?xml version="1.0" encoding="UTF-8"?>
<insiders>
<insider>
<owner id="101912">
<namestrings>
<namestring />
</namestrings>
</owner>
<positionHistory>
<position code="122">
<from />
</position>
</positionHistory>
<linkages>
<linkage>
<owner id="112025">
<namestrings>
<namestring />
</namestrings>
</owner>
<relationshipHistory>
<relationship code="201" />
</relationshipHistory>
</linkage>
</linkages>
</insider>
<insider>
<owner id="100366">
<namestrings>
<namestring>KAITUE KARRI</namestring>
</namestrings>
</owner>
<positionHistory>
<position code="102">
<from>2013-08-07</from>
</position>
</positionHistory>
<linkages>
<linkage>
<owner id="100354">
<namestrings>
<namestring>KAITUE RAIMO KUOLINPESĂ„</namestring>
</namestrings>
</owner>
<relationshipHistory>
<relationship code="302">
<from>1998-10-23</from>
</relationship>
</relationshipHistory>
</linkage>
<linkage>
<owner id="126799">
<namestrings>
<namestring />
</namestrings>
</owner>
<relationshipHistory>
<relationship code="204">
<from>2014-09-09</from>
</relationship>
<relationship code="201">
<to>2014-09-08</to>
</relationship>
</relationshipHistory>
</linkage>
</linkages>
</insider>
</insiders>


I want to sort Code which is in relationship node I have tried below menioned code but it's give me only relationship nodes How can I sort that relationship node with full xml



var Document = doc.Descendants("relationship")
.OrderBy(p =>(int) p.Attribute("code"));

No comments:

Post a Comment