Hello
as*******@hotmail.com,
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