appending xml document in C#

Discussion in 'Software' started by kanjali, Apr 18, 2008.

  1. kanjali

    kanjali

    Joined:
    Mar 26, 2008
    Messages:
    5
    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...:-(
     
    kanjali, Apr 18, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TinCanMan

    Appending to the path statement

    TinCanMan, Jun 2, 2004, in forum: Computer Support
    Replies:
    1
    Views:
    551
    ┬░Mike┬░
    Jun 2, 2004
  2. clement.eric@gmail.com

    Compatibility with MS Office document 32bit with document 64bit

    clement.eric@gmail.com, Sep 14, 2006, in forum: Windows 64bit
    Replies:
    2
    Views:
    491
    clement.eric@gmail.com
    Sep 15, 2006
  3. clement.eric@gmail.com

    Compatibility with MS Office document 32bit with document 64bit

    clement.eric@gmail.com, Sep 14, 2006, in forum: Windows 64bit
    Replies:
    0
    Views:
    477
    clement.eric@gmail.com
    Sep 14, 2006
  4. mnshtiwari
    Replies:
    0
    Views:
    1,526
    mnshtiwari
    Apr 14, 2009
  5. abnerliu
    Replies:
    0
    Views:
    1,148
    abnerliu
    Aug 4, 2011
Loading...

Share This Page