[jdom-interest] JDOM namespace bug?

Cole, Brian bcole at nsf.gov
Mon Apr 16 12:56:34 PDT 2001


Well I knew when you wrote that that you would be
correct, but it took me a while to find it in the spec.
The restriction appears in the syntactic part of the
spec, not in the semantic section where I expected it.

I don't understand the reason for the restriction, though.
The namespace prefixes act as a kind of abbreviation, so

<foo:root xmlns:foo=STRING>
  <foo:one/>
  <foo:two/>
  <foo:three/>
</foo:root>

is the same as

<root xmlns=STRING>
  <one xmlns=STRING/>
  <two xmlns=STRING/>
  <three xmlns=STRING/>
</root>

Or rather, they are the same when STRING is
any string except for the empty string, in which
case the latter is legal but the former is not.

If the spec allows setting an individual tag to
not be in any namespace--which it does--then
why forbid the definition of a prefix that would
do the same thing? I don't get it.


This thread does not really concern JDOM, as
it turns out, so I'll let it die. But let me say this:

JDOM should at least consider being lenient
about this. I remember when a new release of
a popular DNS server (I forget which one) all
of a sudden stopped doing lookups on host
names which contained underscores. The
spec says host names aren't supposed to
contain underscores, so theoretically there
was no problem, but the switch caused trouble
anyway.

Now that I've been warned (thanks, btw) I will change
all my files to be compliant. But unless I'm the only
person doing this, people are going to be surprised
when upgrade to JDOM b7 (or whatever the next
release will be) and their stuff stops working.


Before I leave, let me explain why I was doing things
the way I was. First, I really want the default namespace
of my source XML documents to be the XHTML namespace.
This is because the content of many of the elemets I
defined will be pasted in (or pulled from a db, etc.) from
existing documets. Many of these existing documents
include XHTML markup. I don't want to have to transform
all of the embedded XHTML tags before pasting them in.
(Or rather, I don't really have control over the people who
will be doing this pasting.) Much easier /better to just prefix
all of the tags I've defined with "ej", and define the default
namespace to be XHTML.
So far, it doesn't really matter which namespace URI "ej"
maps to, but read on.)

Second, these XML documents (or more accurately, certain
subtrees of them) will undergo XSLT transformations. (Again,
I don't necessarily have control over the people who will be
writing the XSLT stylesheets. I want to keep things as
easy/simple for them as possible.) I want them to be able to
write a template rule like this:

<xsl:template match="rabbit">

But this only matches <rabbit/> elements that are not in any
namespace. If the <rabbit/> tag is defined to be in some
namespace, then the <xsl:template/> rule _MUST_ be prefixed
with something, like this:

<xsl:template match="ej:rabbit">

You might think (I did once) that you could just define the default
namespace of the XSLT stylesheet to be not in any namespace
(excuse the poor wording, you know what I mean, right? I guess it
should say "you could designate that there is no default namespace")
but that doesn't work. That would apply to any un-prefixed tags, but in

<xsl:template match="rabbit">

"rabbit" is not prefixed, but it's also not a tag. It is matched against
tags in the source document, but it's really just an attribute value.
(This is how Saxon works, anyway. If any other XSLT engines do
apply the default namespace to unprefixed "match=" values, please
let me know.)
So now you see why I wanted "ej:rabbit" to be not in any namespace
in the source document, even though it has a prefix. 

When I changed "ej" to denote some namespace in my source
documents, to be compliant with the spec and the next release of
JDOM, all of my XSLT stylesheets broke. I've fixed many of them,
but I still have lots left to fix.

-brian

> -----Original Message-----
> From:	Jason Hunter [SMTP:jhunter at collab.net]
> Sent:	Wednesday, April 11, 2001 6:22 PM
> To:	Cole, Brian
> Cc:	'jdom-interest at jdom.org'; 'bassclar at world.oberlin.edu'
> Subject:	Re: [jdom-interest] JDOM namespace bug?
> 
> > Here's a sample XML instance file:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <ej:baz xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
> > xmlns:ej="" xmlns="http://www.w3.org/1999/xhtml">
> >         <ej:foo>1 <b>2 3</b> 4 <b>5</b> 6 <b>7</b> 8 9 10 <b>11</b> 12
> > </ej:foo>
> > </ej:baz>
> > 
> >   A call to elt.getNamespace().getPrefix() returns the
> > empty String on both <ej:foo/> and <b/>. I expected
> > it to return "ej" when called on <ej:foo/>. Please see
> > my previous post for more detail.
> > 
> > -brian
> 
> Here's what I get parsing that file with the latest code from CVS:
> 
> % java Tester2 baz.xml
> Exception in thread "main" org.jdom.JDOMException: Error in building:
> The name "" is not legal for JDOM/XML namespaces: Namespace URIs must be
> non-null and non-empty Strings.
> 
> This is what you should see, an error msg that xmlns:ej="" isn't legal. 
> If you read the spec carefully, only a default namespace may have an
> empty attribute value.  This extent of namespace sanity checking is
> relatively new, so your code is just misbehaving because assumptions
> were violated.  Now we check up front.
> 
> -jh-



More information about the jdom-interest mailing list