I have XML stored in string variable:
xxx 000 Defaul
Using the XmlDocument
way, you can do this as follows (and keep the tree intact):
XmlDocument oldDoc = new XmlDocument();
oldDoc.LoadXml("xxx 000 Default ");
XmlNode node = oldDoc.SelectSingleNode("ItemMasterList");
XmlDocument newDoc = new XmlDocument();
XmlElement ele = newDoc.CreateElement("MasterList");
ele.InnerXml = node.InnerXml;
If you now use ele.OuterXml
is will return: (you you just need the string, otherwise use XmlDocument.AppendChild(ele)
and you will be able to use the XmlDocument
object some more)
xxx
000
Default