Solved

xpath selection with namespace and specified node value

Posted on 2009-04-09
7
352 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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now