[jdom-interest] Reading the xml:base attribute

Bradley S. Huffman hip at a.cs.okstate.edu
Thu Jan 6 09:01:44 PST 2005

"Michael Kay" writes:

> No, I might be using a namespace that doesn't appear in the document at all.
> I'm just trying to read the attribute with a given (uri + local-name) and
> get null back if it's not there - and it seems I have to write different
> code for this depending on the value of the URI.

You don't. You just have to stop using Namespace.getNamespace(String uri) as
a "give me a Namespace object with the given URI, and I don't care what prefix
it has", which is not what this method does.  This method returns a Namespace
object (either newly created or cached) with the supplied URI and *no* prefix.
In JDOM a Namespace object always maps a prefix to a URI, and in the case of
the default namespace we use the empty string for the prefix. The two
forms of getNamespace are the factory methods, with getNamespace(uri) being
shorthand for getNamespace("", uri). There is no wildcard for representing
namespace prefixes.

Does JDOM need a getAttribute(String localName, String uri)? So far no one has
screamed loudly for it.


More information about the jdom-interest mailing list