dcsimg
Results 1 to 4 of 4

Thread: write to xml file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2007
    Posts
    694

    write to xml file

    Inside the test.xml file, I have the following xml

    <?xml version="1.0" encoding="utf-8" ?>
    <addresses>
    <address>
    <home>briar road, london</home>
    </address>
    <address>
    <home>clapton street, New York</home>
    </address>
    <address>
    <home>asdanz ave. York</home>
    </address>
    ...
    ...
    ...
    </addresses>

    This xml gets retrieved into a textbox.
    Then I make changes to it, notice that I have removed the xml for
    <address>
    <home>asdanz ave. York</home>
    </address>

    and added xml for
    <address>
    <home>SOME ROAD. london</home>
    </address>

    see below the next xml which is inside the textbox


    <?xml version="1.0" encoding="utf-8" ?>
    <addresses>
    <address>
    <home>briar road, london</home>
    </address>
    <address>
    <home>clapton street, New York</home>
    </address>
    <address>
    <home>SOME ROAD. london</home>
    </address>
    ...
    ...
    ...
    </addresses>

    After changes, I would like to write this new xml into the test.xml file

    Question:
    How do I write this back into the test.xml

    Thanks

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: write to xml file

    You can use the WriteAllText method to write to text file. If you are simply modifying the XML in a textbox, then that is all you should need:

    Code:
     System.IO.File.WriteAllText(@"C:\Path\To\Xml.xml", textBox1.Text);

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2007
    Posts
    694

    Re: write to xml file

    Thank you

  4. #4
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,966

    Re: write to xml file

    If you are storing this xml in an XmlDocument, then you can also call the Save method on it.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width