[jdom-interest] First impressions and some suggestions

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Jun 2 04:56:36 PDT 2000


At 7:21 PM -0700 6/1/00, Jason Hunter wrote:

>I like that this lets you call whichever you prefer, and lets the same
>document easily use both.  I lean toward getContent() returning trimmed
>because I believe that to be more common, more helpful to the beginner,
>and because it's nicely backward compat.
>

The default should be to do what the XML spec requires. That's 
preserving white space. Brett's argues that we can call JDOM an 
application rather than a parser, and that therefore it can do 
whatever it feels like, but that seems a little sophistic to me. 
Programmers will use JDOM in place of the parser's own API, not as a 
separate application like they might use an RSS reader. They'll 
expect it to behave like a parser should behave. In cases where 
programmers don't know every last detail of the XML spec, (e.g. how 
white space is handled, what names are legal) then the API they use 
should protect them from their ignorance. That's a large reason why 
they're using the API instead of writing their own parser. XML is 
complex and tricky. We have to respect that rather than trying to 
deny it.

As has been pointed out by others, some use cases such as XSLT and 
XHTML require that white space be preserved so some programmers will 
expect it to be preserved. Others won't. It's not apparent to me that 
one case is more likely or obvious than the other.

However, what is clear is that if a programmer is expecting white 
space to be thrown away, they should almost immediately notice that 
it isn't and start calling trim(). If they notice that white space is 
being stripped and they don't want it to be, however, then the 
solution is not nearly as obvious.


+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|                  The XML Bible (IDG Books, 1999)                   |
|              http://metalab.unc.edu/xml/books/bible/               |
|   http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://metalab.unc.edu/javafaq/ |
|  Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/     |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list