473,383 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

XML Document - find one row

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
Nov 16 '05 #1
4 5088
Can someone give me some recommendations on source control software for
dotnet projects.

Regards
Dan

Mark wrote:
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

Nov 16 '05 #2
Oops sorry for replying to your thread. I am not used to using this mail
client.

Regards
Daniel

mailer wrote:
Can someone give me some recommendations on source control software for
dotnet projects.

Regards
Dan

Mark wrote:
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

Nov 16 '05 #3
This is my recommendation, assuming we have some XML like this:
<root>
<person name="Bart" ssn="123" />
<person name="Marge" ssn="234" />
</root>
<snippet>
string filename = "C:\people.xml", ssn = "123";
XmlDocument doc = new XmlDocument();
doc.Load(filename);
XmlNode resultNode = doc.DocumentElement.SelectSingleNode
(string.Format("person[@ssn='{0}']", ssn));
if (null != resultNode)
Console.WriteLine("SSN number {0} belongs to {1}!", ssn,
resultNode.Attributes ["name"].InnerText);
else
Console.WriteLine("SSN number {0} does not exist.", ssn);
</snippet>

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #4
Mark,

If you want the quickest way, then I would structure the data so that
the SSN number is in the parent element for each person. Then, I would use
an XmlTextReader to read the XML sequentially from the file. When you come
across a node with the appropriate SSN, then you will know to read the rest
of the nodes for your information, and to not just skip them.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mark" <mf****@idonotlikespam.cce.umn.edu> wrote in message
news:eb**************@TK2MSFTNGP10.phx.gbl...
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

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jari Kujansuu | last post by:
I can successfully parse XML document using SAX or DOM and I can also validate XML document against schema. Problem is that my program should deal with user-defined schemas which means that when...
6
by: David List | last post by:
I'm having a problem using different properties of the document object in the example javascripts in my textbook with browsers that identify themselves as using the Mozilla engine. One example of...
12
by: *.* | last post by:
Hey- I seem to be having a problem with the document.lastModified property. The way it is suppose to work is that it returns the date and time at which the document was last modified. IN my...
1
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.