Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Readin' & Writin'

Status
Not open for further replies.

hitechboy78737

Programmer
Nov 8, 2004
82
US
I have an compact framework application that I would like to use XML files instead of a database to contain the applications data.


What I want to know is it possible to:

1. search the XML for a specific node... and grab the data like you would a recordset and a sql select command

2. write updates to that nodes data, again like you would with a recordset and sql update command

Say I want to find recordid 123456 from the following XML and change the name to John Doe:
Code:
<records>
 <record>
  <recordID>123456</record>
  <name>Sam Sneed</name>
 </record>
 <record>
  <recordID>987654</recordID>
  <name>Billy Ray</name>
 </record>
</records>

I have read much over the last couple of days- and it's left me confused. As I understand it, the XMLReader is forward and read only. Is there a way to specifically find one thing without looping through the whole tree? How would you do that?

Secondly- I just do not understand how I can update that specific data. I even read that the XMLWriter is forward only too.

And lastly- how do you append new data to the end of an existing XML file? The example I looked at a few minutes ago just reproduced the ENTIRE data store and appended the new record to the end of that.

Can someone point me to an easily understandable reference(s) that cover this scenario I've described?

As usual, thanks for the advice and hand-holding!
Kevin Howell
Briefcase of Talent



 
Can I use these objects with XML? If so, can you point me towards that?

There is no provision to use an actual database on this project- XML seemed the best solution. The orgional application wrote its data to comma delimited text files.
 
Do you mean you can't use a db? Or just that it wasn't spec'd?

If you can, use SQL CE. It's great to work with. Less hassel than XML if you're not familiar with all the XML objects and syntax.

Dale
 
The dataset object has .writeXML and .readXML methods. If you're working with data stored in XML, it's by far the easiest way to get at it.

And like Dale said, you can use a light weight database. But since you can use ADO.Net to talk to a DB or XML, they are both just as easy.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
The client doesn't want a lightweight database used in this particular project. They feel that given the constraints that a PPC applies, a database of any sort not going to work into their plan. I don't know that I disagree with them.

Personally, I would perfer using a light weight database as I know how to write against that. However they are hot for an XML solution so I'm making my first dive into the technology.

A couple of questions then:
1. What is the difference betweem the XML namspace objects and the ADO.NET XML objects?

2. Why are the ADO XML objects easier to work with?

3. What are your favorite refereces to give me a good grounding on ADO XML?

Thanks for all of your advice and time!

Kevin Howell
Briefcase of Talent
 
1. What is the difference betweem the XML namspace objects and the ADO.NET XML objects?

The XML Namespace interacts with XML. The ADO.Net namespace interacts with data.

2. Why are the ADO XML objects easier to work with?

With ADO.Net object, you work with data, it does all of the XML work for you.

3. What are your favorite refereces to give me a good grounding on ADO XML?

This site, google, and Visual Studio. Create a datatable, add columns to it, add rows to it, then call datatable.dataset.writexml(filename) and viola, you have all your data writen to XML. Later you can retreive it by creating a data table and calling datatable.dataset.readxml(filename)

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Well Rick... that sounds easy to me... can it possibly be that simple??

Another question. Lets say that I have my data represented in an XML file. I want to update just one element without outputting an "new" xml file in its enterity with the element's changes. Is this possible?

Kevin Howell
 
Kinda sorta. The readXML/writeXML are all at once methods. But you can read the xml, use .select to find the record you are looking for, change the values, and use .writeXML to overwrite the old file with the new file.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Thats what I thought. So would you say that the overhead for XML would be higher or lower than for SQL CE? Rember this is a PocketPC application.
 
One other point... at some point the data collected will be imported into a FileMaker Pro database. Can SQL CE and FileMaker talk to eachother??
 
Not sure about FileMaker/SQL, but it wouldn't supprise me.

XML has a significant amount of overhead no matter how you work with it. That's one of the inherant down sides of it, it stores a LOT of meta data for the data it contains.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top