Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

xpath selection with namespace and specified node value

Posted on 2009-04-09
7
Medium Priority
?
359 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
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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