XML parsing

X

Xarky

Hi,
I'm newbie to XML parsing. I have the following XML document and
would like to extract the age for a specific person.

Can you please give me some specific links, of how I can achieve this.

<tags>
<tag>
<person>
name1
<\person>
<age>
34
<\age>
<\tag>
<tag>
<person>
name2
<\person>
<age>
43
<\age>
<\tag>
<\tags>

Thanks in Advance
 
J

John M Deal

Take a look at these pages on XPath:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmrefxpathexamples.asp
http://msdn.microsoft.com/library/d...-us/xmlsdk/html/xmreflocationpathexamples.asp

You should be able to use it to construct the location statement that
you'll need to use with the SelectSingleNode() method of the XmlDocument
object that you load you Xml into.

Here's a sample of what you'll need for this one:

string name = "name1";
string xpathExpression =
String.Format("/tags/tag/age[preceding-sibling::person='{0}' or
following-sibling::person='{0}']", name);

I'm not in front of a dev box right now so I can't test this out;
however it should be pretty close. Play with it a bit and you'll get it
working.

Have A Better One!

John M Deal, MCP
Necessity Software
 

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

Top