[jdom-interest] I got a Problem with using Namespaces

Jason Hunter jhunter at collab.net
Mon May 28 12:33:06 PDT 2001


Amy Lewis wrote:
> 
> On Mon, May 28, 2001 at 12:19:04PM -0500, philip.nelson at omniresources.com wrote:
> >put the xsi namespace declaration ahead of where it's used 
> > and I think you'll have it.
> 
> If that works, then either the parser or the SAXHandler is not
> spec-compliant.  Attributes do not have order, and namespace
> declarations count (for a change) as attributes in this case.  The
> parser/builder has to accept the whole set of attributes, extract
> namespaces first, then cope with the rest of the things (because
> conceptually, namespaces are declared before their parent element)
> (ain't it grand that XML is so easy to learn?)

I suspect it's a Crimson bug.

Testing myself, it works for Xerces (DOM and SAX both) but with Crimson
I see the error (DOM and SAX both).  What's interesting about the
Crimson error is that the exception isn't thrown from JDOM code.  Here's
the top part of the exception:

Root cause: org.xml.sax.SAXParseException: Undeclared prefix:
"xsi:type".
        at org.apache.crimson.parser.Parser2.error(Parser2.java:3013)
        at
org.apache.crimson.parser.Parser2.processName(Parser2.java:1581)
        at
org.apache.crimson.parser.Parser2.processAttributeNS(Parser2.java:155
3)
  etc

In fact, SAXHandler's startElement() and startPrefixMapping() methods
aren't even called before the error occurs, as evidenced by
out.println()'s.  It's definitely a parser issue.

BTW, to answer Amy's post, in SAX the xmlns attributes shouldn't
actually appear in the Attributes list passed to startElement() but
rather should be reported using the startPrefixMapping() callback.

Anyway, Tobias, you can use the Xerces that comes with JDOM to get
things working right now.  I'll report the bug to the Crimson
developers.  If you're not using Crimson (you didn't include the full
stack trace so I can't tell -- please everyone always include full stack
traces), and another parser has a similar bug, let us know.

-jh-




More information about the jdom-interest mailing list