[jdom-interest] a CDATA implementation

Elliotte Rusty Harold elharo at metalab.unc.edu
Sat Aug 26 07:23:19 PDT 2000


At 11:09 AM +0200 8/26/00, Oliver Imbusch wrote:

>
>    ds> I added a class called org.jdom.CDATA
>
>That's where I don't like it: in the JDOM tree. As Jason points out in
>another posting:
>

You've put your finger on what was bothering me about this proposal. 
I don't want CDATA nodes showing up in the in-memory tree. I wouldn't 
want the existence of CDATA class to change the explicit or implicit 
API. That is I'd like the exact same tree-walking code to work 
whether there was a CDATA class or not. Still, it's going to be hard 
to be faithful to the input in the output if we don't add a CDATA 
class.

Possible solutions:

1. If we used a Text class instead of String directly, then it could 
have an isCDATA attribute, but it was decided long ago not to use a 
separate Text node class instead of String.

2. We could give XMLOutputter some methods to allow the user to 
choose which Strings they wanted to output as CDATA, but I'm not sure 
what that would look like.

3. We could keep CDATA nodes internally, but return them as Strings 
externally. Of course this screws up the live copies of various 
lists. We could no longer simply return the actual PartialList from 
getMixedContent(). Instead we'd need to make a new list that 
converted all CDATA sections to strings and returned that. This 
breaks a lot of JDOM's existing semantics.

4. Maybe the PartialList or the parent element could mark certain 
Strings as CDATA sections somehow. The logic would be convoluted but 
doable. There'd still be problems when a list was copied from one 
element to another though.

Any other ideas? The only one of these ideas that seems remotely 
plausible to me is #1, use a Text class instead of String. This has a 
few other advantages besides like the ability to get the parent or 
position of a Text node. But it would be a major shift in philosophy 
for JDOM.

Frankly, I think at this point we're better off saying CDATA falls on 
the wrong side of the 80/20 split we're trying to hit with JDOM.

+-----------------------+------------------------+-------------------+
| 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