Solved

xpath selection with namespace and specified node value

Posted on 2009-04-09
7
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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