0

I have the following xml node

  <group>
    <level id="1" name="Level 1" />
    <level id="2" name="Level 2" />
  </group>

How can insert new element with it's attributes to xml file

4

1 回答 1

0
var doc = XDocument.Load("yourxmlfile.xml");
var x = new XElement("level", 
         new XAttribute("id", 3), 
         new XAttribute("name", "Level 3"));

doc.Element("group").Add(x);
doc.Save("yourxmlfile.xml");
于 2013-05-20T04:23:50.350 回答