[jdom-interest] Attribute vs text

Jason Hunter jhunter at servlets.com
Sun Sep 3 12:09:24 PDT 2006

Tatu Saloranta wrote:
> --- "J. McConnell" <jdotmc at gmail.com> wrote:
>> Really?  I didn't realize this.  You said "by
>> default" ... does that
>> mean that there is a way to tell JDOM to be more
>> strict?  Are there
>> any reasons not to do this?

The problem with complete sanity checking is that it takes time.  I once 
calculated a build from a file using the SAXBuilder would take 20% 
longer if JDOM did full character-by-character well formedness checking, 
something that you could argue is a complete waste because the SAX 
parser is doing those same checks also.  Some would argue, "You can't 
trust a SAX parser to be fully compatible."  Some others would argue, 
"Give me my 20% speed boost!"

In the end we kept char-by-char sanity checking on by default, which is 
why you caught the null character error, and for expert users we 
provided an UncheckedJDOMFactory you can set on your builder that uses 
class internal calls during a build to avoid the checking.

I think it's a nice way to have your cake and eat it too.

Apart from char-by-char verification, JDOM made the conscious decision 
to allow one circumstance of malformed content, and that's the ability 
to have a document without a root node.  We added that loophole because 
lots of times you want to "steal" the root node from one document to add 
it to another, and if you enforce full well formedness, you must swap 
out the root element you want and replace it with a bogus root element. 
  It reminds me of Indiana Jones putting a sack of sand in place of the 
golden head.  We let you just take the head and forget the sand.  :) 
Now, if you try to *do* something with the malformed document, like 
output it, you get a nice descriptive error.  I think it's a good 
optimization and life simplifier.

> Also, I think part of the reason XOM was written to
> add all such 'optional' checks, to try to make it
> impossible to produce non-wellformed documents.

Right, which makes a good sound bite, but I think "impossible" is too 
strong a constraint.  Sometimes you want speed, and sometimes you want 
convenience, if both can be done safely.


More information about the jdom-interest mailing list