[jdom-interest] Attribute name verification special casing for xml:base

Bradley S. Huffman hip at a.cs.okstate.edu
Mon Jun 17 09:20:59 PDT 2002

Elliotte Rusty Harold writes:

> I think it's best for JDOM to accept this paragraph at 
> least, and not allow other prefixes to be bound to 
> http://www.w3.org/XML/1998/namespace

> Looking at the Namespace class with this in mind I see several bugs:
> 1. We allow other prefixes to be mapped to the 
> http://www.w3.org/XML/1998/namespace namespace. Arguably, this is OK 
> according to Namespaces 1.0, if not Namespaces 1.0 + errata. We may 
> not want to fix it.

+1 Namespaces 1.0 + errata.

> 2. Someone can call Namespace.getNamespace("xml", 
> "http://www.someweirdURI.com") and get the 
> http://www.w3.org/XML/1998/namespace namespace back. This should 
> probably throw an IllegalNameException instead.


> Now back to the Attribute class. The Attribute class is definitely 
> broken with respect to xml:base, xml:lang, and xml:space because of 
> the special casing. You can create such an attribute, but 
> getNamespacePrefix() and getNamespaceURI() return the empty string 
> and getNamespace() returns Namespace.NO_NAMESPACE. If we're going to 
> special case xml:space/xml:lang/xml:base, then we need to add extra 
> code to Attribute to handle the special cases, which can certainly be 
> done. It just makes the Attribute and Verifier classes somewhat more 
> complex.
> Son our options here are:
> 1. Remove the special casing completely from Verifier, and let 
> clients pass in the prefix, local name, and URI when they want to 
> create an xml:base, xml:space, or xml:lang attribute.
> or
> 2. Add xml:base to Verifier and add special casing for names that 
> start xml: to Attribute.
> I think the first solution is cleaner and more consistent with the 
> JDOM model, but I can write a patch for either one.

+1 for first solution.

> I also note that XMLOutputter has some code that doesn't work with 
> the current special casing because whoever wrote it was assuming that 
> the namespaces were in place:
>      protected void printElement(Element element, Writer out,
>                                  int level, NamespaceStack namespaces)
>                         throws IOException {
>          List attributes = element.getAttributes();
>          List content = element.getContent();
>          // Check for xml:space and adjust format settings
>          String space = null;
>          if (attributes != null) {
>              space = element.getAttributeValue( "space",
>                                                 Namespace.XML_NAMESPACE);
>          }
> I don't know or remember who wrote this particular line of code. It 
> might even have been me. But clearly at least some programmers are 
> thinking of xml:space etc. as existing in a namespace. If we stay 
> with special casing, we'll need to fix this too.

Hmmm, this is a bug. If the doc is built with SAXHandler the above code 
works (if qname != local name, SAXHandler parses the qname), if built
by hand it may or may not work depending on which constructor is used. 


More information about the jdom-interest mailing list