Adding new node to existing XmlDocument object

前端 未结 1 1314
梦毁少年i
梦毁少年i 2021-01-04 22:10

I have an xml of following format.


    
        book 1
        author 1             


        
相关标签:
1条回答
  • 2021-01-04 23:02
    XmlDocument doc = new XmlDocument();
    doc.Load("file.xml");
    XmlElement foo = doc.CreateElement("foo");
    XmlElement bar = doc.CreateElement("bar");
    bar.InnerText = "whatever";
    foo.AppendChild(bar);
    doc.DocumentElement.AppendChild(foo);
    doc.Save("file.xml");
    

    see Martin Honnen Post at: Adding a new Node to existing XML document

    0 讨论(0)
提交回复
热议问题