Reading and Writing to XML file

shalan99

Active member
Joined
Jun 1, 2007
Messages
32
Programming Experience
Beginner
Hi everyone,

I've been doin some reading on using the XML Designer in VS.NET to create an XSD schema, create an XML document based on that schema, and generate a dataset from that schema.

I now want to know how to read/write/update/delete data to/from that XML file using VB in WinForms.

Please could someone point me in the direction of a good and thorough tutorial?

I googled for it, but I'm still drawing a blank!

Much thanx
Shalan99
 
I dont quite understand.. But if you use the dataset designer to make an XML file representing your dataset, you can save and load it with teh ReadXml and WriteXml methods
 
Hi again cjard & thanx 4 the response!
(in advance Please forgive me 4 any elementary comments that I may make!!)

A friend shared some video tutorials with me on How to use the XML Designer in VS.NET, from which I've managed 2 create a schema, create an XML file for the data to be stored in, and create a dataset based on that schema.

I am used to using SQL Server DBs to store data, but instead want to use an XML file. I am quite new to data access in .NET so I am still learning as I go along. I want 2 create and distribute a Windows application, so I don't know if using a SQL Express db would be feasible. Cjard, is there a major difference with regards to performance if I use an XML file instead of a relational db like SQL Express?

Also, with regards to your last point, would I not read/write to the dataset which will automatically read/write to the XML file?
 
Hi again cjard & thanx 4 the response!
(in advance Please forgive me 4 any elementary comments that I may make!!)

A friend shared some video tutorials with me on How to use the XML Designer in VS.NET, from which I've managed 2 create a schema, create an XML file for the data to be stored in, and create a dataset based on that schema.

I am used to using SQL Server DBs to store data, but instead want to use an XML file. I am quite new to data access in .NET so I am still learning as I go along. I want 2 create and distribute a Windows application, so I don't know if using a SQL Express db would be feasible. Cjard, is there a major difference with regards to performance if I use an XML file instead of a relational db like SQL Express?

Also, with regards to your last point, would I not read/write to the dataset which will automatically read/write to the XML file?

Err.. I dont really recall seeing anything that uses an XML file like a database. ReadXml and WriteXml are ways of saving a dataset to disk. THey are in NO WAY a replacement for a relational database management system. If you need to store data, use a database. If its only a small amount of read only data, then sure, use a dataset that you read and write out of an xml file

Dont try to use a dataset as a database for complex or large things; even an access database would be preferable to that..
 
oops! now im quite embarrassed! sorry about that. but its ok...its a learning curve for me.

Agreed about the relational database bit tho. I think I need to do a lot more reading on this subject, and more 2 understand datasets and how 2 use them with databases or XML files. I know that a dataset is a local representation of database objects. With that in mind, would I be interacting with a Data Source (DB or XML) in a disconnected fashion thru the dataset?

I do intend to store 2 small sets of data...typically i would have done so in 2 different tables, with one foreign key relation between them. Can i still use an XML file for this?

regards
 
With that in mind, would I be interacting with a Data Source (DB or XML) in a disconnected fashion thru the dataset?
Correct

I do intend to store 2 small sets of data...typically i would have done so in 2 different tables, with one foreign key relation between them. Can i still use an XML file for this?

regards

You can. For example I have a small app that needs to store a moderate amount of data. It is too much for the Settings, and not enough to warrant a DB, so i store it all in a dataset, and just read and write that dsataset xml from and to disk at app startup and shutdown respectively..

I dont think youll find random access of XML files works speedily.. ie using them like a database is a nono.. But they can be used well to store a dataset in between program runs. Ask over in the XML forum.. JohnH will know.
 
not enough to warrant a DB, so i store it all in a dataset, and just read and write that dsataset xml from and to disk at app startup and shutdown respectively..

My scenario sounds very similar. Ok, so my understanding is as follows:
  • datasets work with data sources in a sort of localised, disconnected way
  • doing this helps with db security & also improves performance by not having to connect to the datasource all the time (esp if I had to read data in a timer tick event every 5 minutes for example)
  • I can work with the data itself via the dataset

In that regard I guess where I am lacking in knowledge is how to use the Dataset syntax itself in my code-behind for writing/writing back to/from the dataset or iterating thru "rows" in the dataset to look for a specific values in a "column". I think that is where I need to find a walkthru or tutorial on.

Thank u for all your help tho cjard, u have been very patient with me! I will enquire more from JohnH on XML matters and also look into the ADO.NET forum section.

Cheers!
shalan99
 
Back
Top