score:3

Accepted answer

Use XDocument instead of XElement to preserve the full document.

Dim root As XDocument = XDocument.Load(inFile)
'code to change elements goes here 
root.Save(outFile)

Related Articles