[jdom-interest] Reading the xml:base attribute

Michael Kay mike at saxonica.com
Thu Jan 6 05:44:38 PST 2005


JDOM doesn't offer a method signature

   getAttribute(String lname, String uri)

instead one has to do

   getAttribute(String lname, Namespace.getNamespace(uri))

But this fails if the uri happens to be the XML URI, e.g. if you're trying
to read xml:base. In this case you need to do

   getAttribute(String name, Namespace.XML_NAMESPACE)

Why should an application retrieving an attribute in the XML namespace need
to handle this differently from an attribute in any other namespace?

Suggestion: Namespace.getNamespace(uri) when the uri is the XML namespace
should not fail, but should return Namespace.XML_NAMESPACE. 

Incidentally, I assume the prefix in the Namespace object makes no
difference to the results of getAttribute(), but the documentation doesn't
make this clear.

Also, I've always assumed that Namespace.getNamespace("") returns the
non-namespace, and indeed (looking at the source code) it does, but I now
see that there's nothing in the documentation to justify this assumption.

Michael Kay
http://www.saxonica.com/



More information about the jdom-interest mailing list