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


xpath selection with namespace and specified node value

Posted on 2009-04-09
Medium Priority
Last Modified: 2013-11-11
This xpath works if you take the namespace out of the xml document:

I need an xpath that works with the namespace.

Here's a tool you can use to test:
<ClientPayersInfo xmlns="http://schemas.datacontract.org/2004/07/SageSoftwareHD.Services.Payer" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">

Open in new window

Question by:micahburnett
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
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

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

Author Comment

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']
LVL 60

Accepted Solution

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()
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!


Author Comment

ID: 24111020
I also found this:

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

Author Closing Comment

ID: 31568704
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
LVL 60

Expert Comment

by:Geert Bormans
ID: 24111106

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