Results 1 to 3 of 3

Thread: XML - Writing to an existing file?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    XML - Writing to an existing file?

    Hi,

    I would grately appreciate if anybody could help me out on this problem, i guess it is a basic question but i can't find a simple example of this anywhere. I have a xml file, see below :

    Code:
    <?xml version="1.0" encoding="utf-8" ?> 
    <cars>
    	<car>
    		<make foreign="true">Honda</make>
    		<model>Accord</model>
    		<color>Black</color>
    		<year>1998</year>
    	</car>
    	<car>
    		<make foreign="true">Ford</make>
    		<model>F-150</model>
    		<color>BLue</color>
    		<year>2000</year>
    	</car>
    </cars>
    I simply want to create a web form that can add a new car to this xml file?

    Another question i have is can i populate my xml file into a datagrid ? If yes then can i edit rows within the datagrid and save the changes back to the xml file?

    Final question is it possible to query an xml file using SQL?

    Any help on any of these questions would be grately appreciated.

    Thank you in advance!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: XML - Writing to an existing file?

    You can do all the things you ask, but it is more fiddly with your own XML schema. If you don't mind the XML files being a bit bigger, I'd recommend simply using a DataSet in your code and using its ReadXml and WriteXml methods to read and write the file. One line of code and you have an instant DataSet that can be bound to a DataGrid. One more line of code and the entire DataSet is saved back to the XML file. If you want to keep your current XML schema, you would need to use the XmlDocument class I would guess, although my experience in that area is very limited. The tools provided still make the job relatively easy, compared to say a text file, but it is more complex than simply serailising and deserialising a DataSet.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2002
    Location
    The Twilight Zone
    Posts
    295

    Re: XML - Writing to an existing file?

    Thanks for your feeback. I have managed to populate a Dataset with my xml file and then bind this to a Datagrid. However i am still having problems adding a row to this datagrid and then save this back to the xml file?

Posting Permissions

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



Click Here to Expand Forum to Full Width