Using the XmlDocument method, you can do this as follows (and keep the tree intact):
XmlDocument oldDoc = new XmlDocument(); oldDoc.LoadXml("<ItemMasterList><ItemMaster><fpartno>xxx</fpartno><frev>000</frev><fac>Default</fac></ItemMaster></ItemMasterList>"); XmlNode node = oldDoc.SelectSingleNode("ItemMasterList"); XmlDocument newDoc = new XmlDocument(); XmlElement ele = newDoc.CreateElement("MasterList"); ele.InnerXml = node.InnerXml;
If you now use ele.OuterXml , it returns: (you just need a string, otherwise use XmlDocument.AppendChild(ele) and you can use the XmlDocument object a bit more)
<MasterList> <ItemMaster> <fpartno>xxx</fpartno> <frev>000</frev> <fac>Default</fac> </ItemMaster> </MasterList>
Kyle rozendo
source share