?
Solved

xpath selection with namespace and specified node value

Posted on 2009-04-09
7
Medium Priority
?
357 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 2000 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
Independent Software Vendors: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 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