Sorting of XML file by XMLElement's InnerText

后端 未结 4 793
野性不改
野性不改 2020-12-21 12:41

Please have a look at the XML file. I would like to sort the XML file by tag


  
    ABC&         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-21 13:22

    if you use using System.Xml.Linq;

    then you can get the sorted xlements like this

    var xnodes = oldXDoc.Element("MyRootNode").Elements();
    var sortedXNodes = xnodes.OrderBy(node => Convert.ToInt32( node.Element("Order").Value));
    var newXdoc = new XDocument(new XElement("MyRootNode", sortedXNodes));
    

提交回复
热议问题