Quantcast
Channel: Rename Root Node in XML
Viewing all articles
Browse latest Browse all 6

Rename Root Node in XML

$
0
0

// Create a new Xml doc object with root node as "NewRootNode" and // copy the inner content from old doc object using the LastChild. XmlDocument doc = new XmlDocument("FileName"); XmlElement newRoot = docNew.CreateElement("NewRootNode");XmlDocument docNew = new XmlDocument();docNew.AppendChild(newRoot); // The below line solves the InnerXml equals the OuterXml Problem

newRoot.InnerXml = oldDoc.LastChild.InnerXml; string xmlText = docNew.OuterXml;

// docNew contains the XML Document with replaced Root Node.




Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>