Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] CDATA section serialization

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] CDATA section serialization
  • Date: Fri, 22 Jul 2005 08:25:00 -0400

A thought has occurred to me while experimenting with Wolfgang's latest optimizations. This isn't an optimization one way or the other, really. It just happened to come up when I was looking at that code. Consider this unusual case:

<element>Text<[![CDATA[data]]>Text<[![CDATA[data]]>Text</element>

A slightly more common variation might be:

<element>
<[![CDATA[data]]>
</element>

However it's basically a text node that contains one or more CDATA sections as well as some text outside CDATA sections. Currently when XOM encounters this it represents it as plain text. That is,

<element>TextdataTextdataText</element>

That is, it uses a regular text node and throws away the CDATA sections. There's no way XOM can preserve the multiple plain texts and CDATA sections because it accumulates all text nodes into a single node on parsing. However, instead of using a single Text object here it could use a single CDATASection object. That is, it could instead produce this:

<element><[![CDATA[TextdataTextdataText]]></element>

Because the CDATASection class is hidden in the non-public API, this really only affects output from toXML and the Serializer. Would this be preferable? Or is it better to just output plain text with appropriate escapes when mixing CDATA sections with content in non-CDATA sections?

The semantic effect here is (or should be) nil. It's really just a question of aesthetic preference.

--
Elliotte Rusty Harold elharo AT metalab.unc.edu
XML in a Nutshell 3rd Edition Just Published!
http://www.cafeconleche.org/books/xian3/
http://www.amazon.com/exec/obidos/ISBN=0596007647/cafeaulaitA/ref=nosim




Archive powered by MHonArc 2.6.24.

Top of Page