XDocument doc = XDocument.Parse(_data)
XElement root = new XElement("student");
doc.Element("marks").Add(root);
doc.Save(_data)
the _data is the deserialized string xml and student is the root tag want to add
doc.save throws the error.How to save the root tag ?
the string xml
<marks>
<name>Martin</name>
<date>3/24/2012</date>
<field>Percent</name>
<new>33.3</new>
<old>10</old>
</marks>
this is the string xml before root tag is added, once it is added it should look like
after the root tag is added it should look like
<student>
<marks>
<name>Martin</name>
<date>3/24/2012</date>
<field>Percent</name>
<new>33.3</new>
<old>10</old>
</marks>
</student>
implies that
_datais XML, ie"<tag> <sub /> </tag>"Requires
_datato be a valid filename. Like"output.xml"Ok, seems that you need:
Take 3:
You need to add the existing xml to
<Student>, not the other way around.