How to add new element below existing element using xml Document

前端 未结 3 1343
生来不讨喜
生来不讨喜 2020-12-17 01:59

I have an element Name \"Dispute\" and want to add new element name \"Records\" below the element.
Eg: The current XML is in this format


         


        
3条回答
  •  难免孤独
    2020-12-17 02:58

    XmlDocument doc = new XmlDocument();
    doc.Load("input.xml");
    
    XmlElement records = doc.CreateElement("Records");
    records.InnerText = Guid.NewGuid().ToString();
    doc.DocumentElement.AppendChild(records);
    
    doc.Save("output.xml"); // if you want to overwrite the input use doc.Save("input.xml");
    

提交回复
热议问题