Change XML root element name

后端 未结 5 796
星月不相逢
星月不相逢 2021-01-12 02:40

I have XML stored in string variable:

xxx000Defaul         


        
5条回答
  •  Happy的楠姐
    2021-01-12 03:38

    System.Xml.XmlDocument and the associated classes in that same namespace will prove invaluable to you here.

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(yourString);
    XmlDocument docNew = new XmlDocument();
    XmlElement newRoot = docNew.CreateElement("MasterList");
    docNew.AppendChild(newRoot);
    newRoot.InnerXml = doc.DocumentElement.InnerXml;
    String xml = docNew.OuterXml;
    

提交回复
热议问题