473,320 Members | 2,041 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,320 software developers and data experts.

What is wrong with my XPathExpression?

I have an XML file that looks like this:

<Counties>
<County>
<District>2</District>
<CountyName>Palm</CountyName>
</County>
<County>
<District>3</District>
<CountyName>McCarthy</CountyName>
</County>
</Counties>

I am trying to use a XPathExpression and XPathNodeIterator to grab the value
of county's district by passing the name of the county in:

....
Dim sr As System.IO.StringReader
sr = New System.IO.StringReader(XMLfile)
Dim xpd As System.Xml.XPath.XPathDocument = New
System.Xml.XPath.XPathDocument(sr)
Dim xpn As System.Xml.XPath.XPathNavigator = xpd.CreateNavigator()
Dim expr As System.Xml.XPath.XPathExpression =
xpn.Compile("//District[../CountyName = '" & countyName & "']")
Dim ni As System.Xml.XPath.XPathNodeIterator = xpn.Select(expr)
ni.MoveNext()
....

if countyName = Palm, I want to return the value of 2

However, the above ALWAYS returns the entire set of data as such:

2Palm3McCarthy

Why is that?

-Darrel
Jun 15 '07 #1
2 2300
However, the above ALWAYS returns the entire set of data as such:
>
2Palm3McCarthy

Why is that?
....because it's NOT finding a node! Ok, I figured that much out...now need
to figure out why it's not actualy finding a node...

-Darrel
Jun 15 '07 #2
darrel wrote:
I have an XML file that looks like this:

<Counties>
<County>
<District>2</District>
<CountyName>Palm</CountyName>
</County>
<County>
<District>3</District>
<CountyName>McCarthy</CountyName>
</County>
</Counties>

I am trying to use a XPathExpression and XPathNodeIterator to grab the value
of county's district by passing the name of the county in:

...
Dim sr As System.IO.StringReader
sr = New System.IO.StringReader(XMLfile)
Dim xpd As System.Xml.XPath.XPathDocument = New
System.Xml.XPath.XPathDocument(sr)
Dim xpn As System.Xml.XPath.XPathNavigator = xpd.CreateNavigator()
Dim expr As System.Xml.XPath.XPathExpression =
xpn.Compile("//District[../CountyName = '" & countyName & "']")
Dim ni As System.Xml.XPath.XPathNodeIterator = xpn.Select(expr)
ni.MoveNext()
...

if countyName = Palm, I want to return the value of 2

However, the above ALWAYS returns the entire set of data as such:

2Palm3McCarthy

Why is that?
You do not show how you output the result.
Also it seems if you are looking for a single result then you could use
SelectSingleNode instead of Select (with .NET 2.0).


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 16 '07 #3

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
2
by: Steve Taylor | last post by:
Is there some reason why I shouldn't be able to use the same XPathExpression simultaneously in multiple iterations? The test below illustrates the problem. It seems that creating two...
4
by: viditmittal | last post by:
hi, i have a xml file <root> <Type /> <Description /> <Category /> <employee > <id>3</id>
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
0
by: LockyBoy | last post by:
Hi Have created an xml document with an xmltextwriter with a namespace, so it can be validated against an xsd schema. Later in my application, I want to extract values from the xml and am using...
0
by: darrel | last post by:
I have a function that I pass some variables to, that then goes into an XML file and returns some other values: dim expr as System.Xml.XPath.XPathExpression = xpn.Compile("//" & variableToReturn...
1
by: jakebbohio | last post by:
I have a user-defined XPath function implemented using a custom context and the IXsltContextFunction interface. For its arguments, it accepts 3: { XPathResultType.Any, XPathResultType.Any,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.