Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

Re: [jdom-interest] Possible bug in SAXHandler when "namespaces" feature is off

Dmitri Plotnikov

2004-01-18

Replies:

Doctor,

This issue came up when I was adding support for "external namespace
registration" to JXPath. There was a discussion on commons-dev@(protected)
regarding the need to register namespaces externally. I decided to add
support to this "feature" to JXPath and discovered that it was a no-brainer
with DOM and impossible with JDOM. See, in order for external namespaces to
make any sense, I first need to be able to read a file that has unmapped
prefixes.

Let's say I want to parse this file:
<my:element>foo</my:element>

True, it does not comply with XML Namespaces, because "my" is not explicitly
mapped to a namespace URI in the same file. But I need to parse this anyway.
So, I turn off the "namespaces" feature. Works like a charm with DOM. Why
should JDOM be less flexible? Or is there a better way?

Here's another argument. JDOM has great flexibility in regards to underlying
SAX driver: you can provide your own if you want to. Since SAXDriver is not
supposed to have namespaces=true, JDOM should really be prepared to handle
the situation.

Finally, even if JDOM is not designed to work with SAX drivers that do not
support namespaces, why doesn't it report that explicitly by throwing a
relevant exception? Why doesn't it check that the driver in fact supports
the feature? A simple call to getFeature(), checking the result and
throwing an exception would do.

Thanks,

- Dmitri

----- Original Message -----
From: "Elliotte Rusty Harold" <elharo@(protected)>
To: "Dmitri Plotnikov" <dmitri@(protected)>
Sent: Saturday, January 17, 2004 8:53 PM
Subject: Re: [jdom-interest] Possible bug in SAXHandler when "namespaces"
feature is off


> >I've noticed that if I turn off the "namespaces" feature, JDOM fails with
> >the following exception:
> >
>
> Patient: Doctor, it hurts when I turn off the "namespaces" feature.
> Doctor: Don't turn off the namespaces feature.
>
> Seriously, JDOM is designed to be namespace aware, and will not
> handle namespace aware and will not handle namespace malformed
> documents. Use the defaults and everything should be fine. Just
> because your documents don't use namespaces, doesn't mean you have to
> turn off the namespaces feature. You would only turn this off if your
> documents used colons in ways prohibited by Namespaces in XML, in
> which case you cannot use JDOM.
> --
>
>   Elliotte Rusty Harold
>   elharo@(protected)
>   Effective XML (Addison-Wesley, 2003)
>   http://www.cafeconleche.org/books/effectivexml
>
http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA
>
>

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.