I have some XML
<Users>
<User Name="Z"/>
<User Name="D"/>
<User Name="A"/>
</User>
I want to sort that by Name. I load that xml using XDocument
. How can I view that xml sorted by Name?
You can sort using LINQ to Xml, if XmlDocument is not the case
XDocument input = XDocument.Load(@"input.xml");
XDocument output = new XDocument(
new XElement("Users",
from node in input.Root.Elements()
orderby node.Attribute("Name").Value descending
select node));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With