[jdom-interest] The JDOM Model, Chapter 15 of Processing XML with Java

Elliotte Rusty Harold elharo at metalab.unc.edu
Tue May 7 09:06:43 PDT 2002


At 11:24 AM -0400 5/7/02, Alex Rosen wrote:


>Interesting, I kind of have the opposite view from you (and unfortunately
>from the XPath people). If you're using a document that has no mixed
>content, then the getText() rules (no recursion) and the XPath rules
>(recursion) are identical.

You see, I don't believe that you can say "My documents don't have 
mixed content" unless you've validated them with that constraint 
before processing. Sooner or later, you will encounter a document 
that does have mixed content, whether you expect it to or not, and 
whether it's allowed or not.

>If your document may have mixed content, then the
>XPath rule is useful 99% of the time but dangerous 1% of the time. Dangerous
>meaning that it can lose information silently, unexpectedly, and with no
>warning. See
>http://www.servlets.com/archive/servlet/ReadMsg?msgId=118234&listName=jdom-i
>nterest

It's a good example. It stumped me at the time. The specific case is

"<p>Thou shalt <strong>NOT</strong> commit adultery.<p>"

vs.

"<p>The dosage is 3<sup>2</sup>
milligrams.</p>". (<sup> means superscript.) Now you've just killed the
patient. :)

Now, however, I wonder about this?

"<p>Do <strong>NOT</strong> give this patient penicillin.<p>"

My basic response is that "Java is not intended for nuclear power 
plants, etc." I do think we're better off handling the 99% case than 
the 1% case. Of course, you could argue that we shouldn't provide 
either method since both are potentially life threatening, but in 
that case programmers are likely to just retrieve the first text node 
and use that, which is worse still, and of course we've just made 
JDOM noticeably harder to use.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list