Append XML string block to existing XmlDocument

前端 未结 6 1477
礼貌的吻别
礼貌的吻别 2020-12-14 15:29

I have an XmlDocument that already exists and is read from a file.

I would like to add a chunk of Xml to a node in the document. Is there a good way to create and a

6条回答
  •  悲哀的现实
    2020-12-14 16:07

    As an alternative, this is how you could do it in a more LINQy 3.5 manner:

     XDocument doc = XDocument.Load(@"c:\temp\test.xml");
     XElement demoNode = new XElement("Demographic");
     demoNode.Add(new XElement("Age"));
     demoNode.Add(new XElement("DOB"));
     doc.Descendants("Employee").Single().Add(demoNode);
     doc.Save(@"c:\temp\test2.xml");
    

提交回复
热议问题