XML document

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have a single XML file containing forty records, with no child nodes. For
example, imagine a list of people's names, and birthdates with SSN.

I'd like to find the row of a person with SSN of 123456789. What's the
quickest way to:

1. Load the file from disk.
2. Find the "record" I want.
3. Walk through the other "fields" in this record to get birthdate, first
name and last name for this person?

For example, should I load the file into a DataSet, or use the XMLDocument
class? I will NOT be binding the data to a DataGrid or similar.

Thanks in advance.
Mark
 
I have a single XML file containing forty records, with no child nodes. For
example, imagine a list of people's names, and birthdates with SSN.

I'd like to find the row of a person with SSN of 123456789. What's the
quickest way to:

1. Load the file from disk.
2. Find the "record" I want.
3. Walk through the other "fields" in this record to get birthdate, first
name and last name for this person?

For example, should I load the file into a DataSet, or use the XMLDocument
class? I will NOT be binding the data to a DataGrid or similar.

With only forty records, speed probably shouldn't be your biggest
concern. Forty records are going to be read pretty quickly no matter
which class you use.

Still, for the general question, I'd say both of the above are the wrong
choice. Both require the entire file to be parsed into classes, and you
only want a little bit of the file. An XmlReader is probably the
fastest solution, but in this case I'd use an XPathNavigator, which is
faster than an XmlDocument or DataSet but still trivial to parse out
information from...

Imports System.Xml.XPath

Dim doc as new XPathDocument(filename)
Dim navigator as XPathNavigator = doc.CreateNavigator()

Dim iter As XPathNodeIterator = navigator.Select("/person[@ssn='123456789']")
If iter.MoveNext Then
Dim ssn As String = iter.Current.GetAttribute("ssn", "")
Dim fname As String = iter.Current.GetAttribute("fname", "")
...
 
load it into a dataset and use the data objects and commands on it to filter
it down to that (mainly the dataview object)
 
Mark,

Because there are different opinions,

I go in this case definitly for the dataset. However it can be a matter of
choise, when you are very well knowed with the XMLreader, than you can as
well take this one. Performance is no decisor in this and as David wrote,
they both have to be loaded first.

However thinking about loading a 40 row dataset from approx 40 characters is
spending time.

There are people who loads datassets from more than 10000 rows. (And there
are reasons for that think on ofline processing)

Cor
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top