kanjali 0 Newbie Poster

HI,

I need to append new tags to the existing xml document.
PLease review this code ,

string txt = TextBox1.Text.ToString();
XmlDocument doc= new XmlDocument();
doc.LoadXml(txt);
XmlElement el = doc.CreateElement("property1");
el.SetAttribute("name1", "C1");
el.InnerText = "This row is being appended to the end of the document.";
doc.DocumentElement.AppendChild(el);
doc.Save(txt);

This code will be helpful to create the childnode, but iam looking for appending Root node as well as childnodes.
Please help me to extend this code for Root nodes.

Note : no need to create XmlDeclaration statement becoz it will be thr for selected xml file by default.

Appreciate your precious reply.

Thanks a lot,
Anjali...:(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.