Private Function orderXML(ByVal myXMLDoc As XmlDocument) As XmlDocument ' Create an xmlString (XElement) ' And converts an XmlElement (in xmlDocument myXMLDoc) to an XElement Dim xmlString As XElement = XElement.Load(myXMLDoc.CreateNavigator.ReadSubtree) Dim xElemLINQ = From x In xmlString.<Design> Order By x.Attribute("ID").Value Dim newNodes = xElemLINQ.ToArray xmlString.Elements.Remove() For Each x As XElement In newNodes xmlString.Add(x) Next ' newXmlDoc.ReadNode(xmlString.CreateReader) to converts an XElement to an XmlElement Dim mySortedXMLDoc As New XmlDocument Dim xmlOutput As XmlElement = CType(mySortedXMLDoc.ReadNode(xmlString.CreateReader), XmlElement) ' Create a StringWriter associated to a XmlTextWriter Dim sw As New StringWriter Dim xw As New XmlTextWriter(sw) ' Then, write the XML to the XMLTextWriter and use the StringWriter to make it a temporary String xmlOutput.WriteTo(xw) Dim tempString As String = sw.ToString() ' Finally, load the temporary String into the original XmlDocument myXMLDoc myXMLDoc.LoadXml(tempString) Return myXMLDoc End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionmyXMLDoc.ReadNode(xmlString.CreateReader) 'Converts an XElement to an XmlElement