Rearrange xml elements.

newguy

Well-known member
Joined
Jun 30, 2008
Messages
611
Location
Denver Co, USA
Programming Experience
1-3
I was wondering, is there a way to rearrange the elements of an xml file? And also, even when they have child nodes? Via code? (VB.Net 2008)

VB.NET:
<main>
  <x1 />
  <x2>
    <y1 />
  </x2>
  <x3 />
</main>
to:

VB.NET:
<main>
  <x1 />
  <x3 />
  <x2>
    <y1 />
  </x2>
</main>
 
Last edited:
VB.NET:
Dim doc As New Xml.XmlDocument
doc.Load(filename)
Dim root = doc.DocumentElement
root.AppendChild(root.SelectSingleNode("x2"))
doc.Save(filename)
 
Back
Top