Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > XML - traversing in VB

Reply
Thread Tools

XML - traversing in VB

 
 
Asad
Guest
Posts: n/a
 
      04-16-2004
Hi, I have an XML file that looks something like this:

- <Geo>
<state>Alabama</state>
<capital>Montgomery</capital>
<abbrev>AL</abbrev>
<timezone>C</timezone>
</Geo>
- <Geo>
<state>Alaska</state>
<capital>Juneau</capital>
<abbrev>AK</abbrev>
<timezone>A</timezone>
</Geo>

so on and so forth. I want to write a function in VB, where if the
function is sent AL (abbreviation) it returns the state name or some
other information in that group. I worked with XML long time ago, and
can't recall right now how to do this. Can someone refresh my memory?
BTW, I want to use XMLTextReader to do this.

Thanks.
 
Reply With Quote
 
 
 
 
Matt Berther
Guest
Posts: n/a
 
      04-16-2004
Hello ,

> Hi, I have an XML file that looks something like this:
>
> - <Geo>
> <state>Alabama</state>
> <capital>Montgomery</capital>
> <abbrev>AL</abbrev>
> <timezone>C</timezone>
> </Geo>
> - <Geo>
> <state>Alaska</state>
> <capital>Juneau</capital>
> <abbrev>AK</abbrev>
> <timezone>A</timezone>
> </Geo>
> so on and so forth. I want to write a function in VB, where if the
> function is sent AL (abbreviation) it returns the state name or some
> other information in that group. I worked with XML long time ago, and
> can't recall right now how to do this. Can someone refresh my memory?
> BTW, I want to use XMLTextReader to do this.


I dont think that you'll be able to use an XmlTextReader to accomplish this, since the XmlTextReader is a forward only cursor through the Xml.

I would think that the best way to accomplish this would be to load the document in an XmlDocument and then use an XPATH query to get the appropriate Geo node.

Example (Excuse the C# code. My VB.NET is rusty):
XmlNode node = document.SelectSingleNode("/Geo[Abbrev = 'AL']");
string stateName = node["state"].InnerText;

Since this Xml is more than likely readonly, you could also look at using the XPathNavigator class to increase performance a little.

HTH!

--
Matt Berther
http://www.mattberther.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with traversing an XML structure Michaelp Perl Misc 0 08-06-2009 12:20 PM
Traversing Hash or XML? Which is Fast thomson ASP .Net 0 12-27-2005 05:57 AM
Traversing properties with a datagrid nmosafi@gmail.com ASP .Net 4 01-04-2005 04:08 PM
Traversing an XML Schema possible? M XML 0 08-05-2004 09:02 AM
Traversing Access types in Modelsim steven VHDL 6 08-27-2003 01:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57