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

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Jun 17 05:09:08 PDT 2002


At 10:41 PM -0700 6/16/02, Jason Hunter wrote:
>Strictly speaking, would "foo:space" be legit and operate the same as
>"xml:space" if the "foo" prefix mapped to the standard XML namespace
>URI?  If so, then I'm OK with passing it in as normal.  If not, it's a
>special case since the prefix is hard-coded.
>

That's a tough one. I think the answer is "No", at least in practice 
and perhaps in theory. They have to be named 
xml:space/xml:lang/xml:base, not foo:space/foo:lang/foo:base; but I'm 
not 100% sure of that.

OK. I just found something. Erratum NE05 states:

The prefix xml is by definition bound to the namespace name 
http://www.w3.org/XML/1998/namespace. It may, but need not, be 
declared, and must not be bound to any other namespace name. No other 
prefix may be bound to this namespace name.

Note, however, that this erratum is extremely controversial (mostly 
for what's in the next paragraph, not for this one) and not everyone 
excepts it as normative. The remainder of this erratum is clearly 
incompatible with Namespaces 1.0, SAX 2.0, and more. However, for the 
case at hand, 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.

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.

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.

-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list