commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [JXPath] Namespace prefixes
Date Wed, 17 Mar 2004 16:16:22 GMT


I'm having the same problem as Sudhir a while ago.

He posted a good example that I'll repeat here:

   I have a fairly simple xml document:

   <?xml version="1.0"?>
   <bk:book xmlns:bk=''
      <bk:title>Cheaper by the Dozen</bk:title>

   To access say the isbn number I would use the following xpath in my

   Note that I need to specify the prefixes in my xpath or it won't work.

   Now if I had instead the following document which is identical for all
   practical purposes with the earlier xml except that the prefixes are
   different, it is my opinion that my code still ought to work.

   <?xml version="1.0"?>
   <ck:book xmlns:ck=''
      <ck:title>Cheaper by the Dozen</ck:title>

   But it doesn't. And that is because the prefixes I am specifying in my
   xpaths are not the same as what is used in the document.

Dmitri implemented a NamespaceManager which would be a good solution to the
problem, but his patch got reversed.

The problem remains however.

Another less intrusive solution would be a setNamespace(String prefix,
String URI) function on a JXPathContext object.
This way all functionality that's present in Xalan is present in JXPath.
As for XPaths on Java-objects, you could ignore all namespaces or disallow
namespace qualifiers. I don't know what happens today if you specify a
namespace, but the behaviour could stay thesame.

I'd very much like this namespace-prefix mapping feature to be
reconsidered, as currently JXPath isn't really usable for removing silly
DOM-navigation-code when the Document uses namespaces.

Nick Hofstede

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message