How can I sort an XDocument by attribute?

后端 未结 2 1538
一个人的身影
一个人的身影 2020-12-11 15:47

I have some XML


    
    
    

I want t

2条回答
  •  一生所求
    2020-12-11 16:17

    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));
    

提交回复
热议问题