How to add root tag to the string xml

barbaratrize

New Member
\[code\] XDocument doc = XDocument.Parse(_data) XElement root = new XElement("student"); doc.Element("marks").Add(root); doc.Save(_data)\[/code\]the _data is the deserialized string xml and student is the root tag want to adddoc.save throws the error.How to save the root tag ?the string xml\[code\] <marks> <name>Martin</name> <date>3/24/2012</date> <field>Percent</name> <new>33.3</new> <old>10</old> </marks> \[/code\]this is the string xml before root tag is added, once it is added it should look likeafter the root tag is added it should look like\[code\] <student> <marks> <name>Martin</name> <date>3/24/2012</date> <field>Percent</name> <new>33.3</new> <old>10</old> </marks> </student>\[/code\]
 
Back
Top