Post details: xpath and namespaces

Aug 31, 2005 : xpath and namespaces

After a lot of googling, I finally found how to get xpath and xml namespaces to work together. The way I ended up doing it was this to duplicate the default namespace and reference it everywhere.

XML file:
<web-app xmlns="" xmlns:j2ee="" ...>


Comments, Pingbacks:

Comment from: Brian Ewins [Visitor] ·
I think you're getting overly hung up on the prefixes.

[web-app xmlns=""...]

with the xpath:

will work too as long as foo is bound to the namespace "" in your xpath processor. Its unclear what the context of the xpath is you struggled with, but in xsl, you can use this like:

[xsl:stylesheet xmlns:xsl="..." xmlns:foo=""]
[xsl:template match="//foo:web-app/foo:servlet[foo:servlet-name='myapp']"]...[/xsl:template]

remember prefixes are just aliases, and prefixes in the stylesheet are nothing to do with those in the processed document.

In xpath libraries (eg jaxen) theres usually some other way of binding prefixes to namespaces, but those prefixes are only relevant in the xpath itself.
Permalink 08/31/05 @ 11:51
Comment from: Dave Brondsema [Member] ·
Thanks for the additional info. I am using the ant xmltask from and it does not appear to have any support for configuring the xpath processor it uses.
Permalink 08/31/05 @ 12:35

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.
What is the 2-letter abbreviation for Michigan?
Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email & url)

<  January 2020  >
Mon Tue Wed Thu Fri Sat Sun
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    




Syndicate this blog XML

powered by