[jdom-interest] Reading the xml:base attribute
Bradley S. Huffman
hip at a.cs.okstate.edu
Thu Jan 6 07:34:56 PST 2005
"Michael Kay" writes:
> 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.
As it should. From Namespace.getNamespace(String) javadoc
This will retrieve (if in existence) or create (if not) a Namespace for
the supplied URI, and make it usable as a default namespace, as no prefix
is supplied.
And you cann't map http://www.w3.org/XML/1998/namespace to the default
namespace.
> In this case you need to do
>
> getAttribute(String name, Namespace.XML_NAMESPACE)
Or getAttribute(name, Namespace.getNamespace("xml", "http://www.w3.org/XML/1998/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.
JDOM currently doesn't have such a method, but are you looking for a
getInScopeNamespace(String uri)?
Brad
More information about the jdom-interest
mailing list