473,796 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is wrong with my XPathExpression ?

I have an XML file that looks like this:

<Counties>
<County>
<District>2</District>
<CountyName>Pal m</CountyName>
</County>
<County>
<District>3</District>
<CountyName>McC arthy</CountyName>
</County>
</Counties>

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

....
Dim sr As System.IO.Strin gReader
sr = New System.IO.Strin gReader(XMLfile )
Dim xpd As System.Xml.XPat h.XPathDocument = New
System.Xml.XPat h.XPathDocument (sr)
Dim xpn As System.Xml.XPat h.XPathNavigato r = xpd.CreateNavig ator()
Dim expr As System.Xml.XPat h.XPathExpressi on =
xpn.Compile("//District[../CountyName = '" & countyName & "']")
Dim ni As System.Xml.XPat h.XPathNodeIter ator = 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 2324
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>Pal m</CountyName>
</County>
<County>
<District>3</District>
<CountyName>McC arthy</CountyName>
</County>
</Counties>

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

...
Dim sr As System.IO.Strin gReader
sr = New System.IO.Strin gReader(XMLfile )
Dim xpd As System.Xml.XPat h.XPathDocument = New
System.Xml.XPat h.XPathDocument (sr)
Dim xpn As System.Xml.XPat h.XPathNavigato r = xpd.CreateNavig ator()
Dim expr As System.Xml.XPat h.XPathExpressi on =
xpn.Compile("//District[../CountyName = '" & countyName & "']")
Dim ni As System.Xml.XPat h.XPathNodeIter ator = 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
SelectSingleNod e 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
14860
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
72
5900
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 example, between a C/C++ programmers with a few weeks of experience and a C/C++ programmer with years of experience. You don't really need to understand the subtle details or use the obscure features of either language
121
10186
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
2
2769
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 XPathNodeIterators with the same expression creates a coupling between the iterators so they always point to the same position. Anyone care to comment? public void ReuseCompiledExpr() { XmlDocument doc = new XmlDocument();
4
4511
by: viditmittal | last post by:
hi, i have a xml file <root> <Type /> <Description /> <Category /> <employee > <id>3</id>
13
5060
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
1055
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 xpathexpression. Because I have a namespace in the xml, I have to use the xmlNameSpaceManager and comile an xpathquery as below:
0
859
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 & "") dim ni as System.Xml.XPath.XPathNodeIterator = xpn.Select(expr) ni.MoveNext() if ni.Current.Value <> "" then
1
2074
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, XPathResultType.String }. The function is called datediff, which converts the arguments to DateTimes, and gives args - args in the units specified by args (e.g., "days", "months"). Anyhow, as an example, Let's say I have the following XML file: ...
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10453
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10172
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.