1

For the following XML instance:

<foo:a xmlns:foo="http://foo"> <b> whatever </b>   </foo:a>

One can use the local-name(/*) and name(/*) XPath expressions to get a and foo:a respectively (as shown in this SO post).

Are there any XPath expressions to:

  • get me the namespace binding of the root -or any other- element (http://foo)
  • directly get me the namespace prefix of the root -or any other- element (foo)
3
  • Does your XML really have the backslashes in it? Commented Oct 11, 2013 at 18:42
  • 1
    I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not". Commented Oct 11, 2013 at 18:43
  • @JohnSaunders re the backlashes, no my bad I copy-pasted the XML out of a String literal in code, have now fixed that. Commented Oct 11, 2013 at 18:47

2 Answers 2

2

You can use namespace-uri:

namespace-uri(/*)
Sign up to request clarification or add additional context in comments.

1 Comment

And as for the other question, the only way to get the prefix is to use name() and extract the part before the colon.
2

I've found this works to get the prefix (xpath 2.0):

prefix-from-QName(node-name())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.