Solved

xpath selection with namespace and specified node value

Posted on 2009-04-09
7
355 Views
Last Modified: 2013-11-11
This xpath works if you take the namespace out of the xml document:
//ClientPayerRelationshipInfo[PayerId='1-87EIF9']/PayerId/text()

I need an xpath that works with the namespace.

Here's a tool you can use to test:
http://www.mizar.dk/XPath/Default.aspx
<ClientPayersInfo xmlns="http://schemas.datacontract.org/2004/07/SageSoftwareHD.Services.Payer" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
	<ClientId>V8-S2</ClientId>
	<ClientPayerRelationships>
		<ClientPayerRelationshipInfo>
			<LobInstitutional>true</LobInstitutional>
			<LobProfessional>true</LobProfessional>
			<PayerId>1-87EIBP</PayerId>
		</ClientPayerRelationshipInfo>
		<ClientPayerRelationshipInfo>
			<LobInstitutional>true</LobInstitutional>
			<LobProfessional>true</LobProfessional>
			<PayerId>1-87EIF9</PayerId>
		</ClientPayerRelationshipInfo>
	</ClientPayerRelationships>
	<CurrentlyUseEmdeon>true</CurrentlyUseEmdeon>
</ClientPayersInfo>

Open in new window

0
Comment
Question by:micahburnett
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24110832
Well, such an XPath largely depends on the XPath processor you use
(I did not see immedeatly how to bind a namespace in the simple tester  you suggested)

In any programming language, you would usually need a NamespaceManager
In the NamespaceManager you bind the namespace to a prefix
and then you use the prefix in the XPath
//dc:ClientPayerRelationshipInfo[dc:PayerId='1-87EIF9']/dc:PayerId/text()

You can always make your XPath namespace independent, but that will be a lot slower
//*[local-name() = 'ClientPayerRelationshipInfo'][*[local-name() = 'PayerId']='1-87EIF9']/][*[local-name() = 'PayerId']/text()

Try to find a way to add a namespacemanager in the tool you will eventually use to execute the XPath
0
 
LVL 2

Author Comment

by:micahburnett
ID: 24110935
I don't mind going namespace independent as long as I can select only the node that has the value I'm looking for.  I don't think your second xpath is valid.

This partially works, but I need only the node I'm looking for:
//*[local-name() = 'ClientPayerRelationshipInfo']/*[local-name() = 'PayerId']
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24111007
My second XPath indeed is not valid, I have a ][ too much, that happens when you use the browser as an XPath editor :-)
try this
//*[local-name() = 'ClientPayerRelationshipInfo'][*[local-name() = 'PayerId']='1-87EIF9']/*[local-name() = 'PayerId']/text()
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 2

Author Comment

by:micahburnett
ID: 24111020
I also found this:

//*[local-name() = 'ClientPayerRelationshipInfo']/*[local-name() = 'PayerId' and text()='1-87EIF9']
0
 
LVL 2

Author Closing Comment

by:micahburnett
ID: 31568704
Thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24111058
well, I started from your original XPath
My last XPath and yours are only equivalent if a ClientPayerRelationshipInfo has only one PayerId
(which seems to be the case from the example)
Then yours is shorter (and better) of course
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24111106
welcome
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question