<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7650.28">
<TITLE>CDATA outputting issue</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->

<P><FONT SIZE=2 FACE="Arial">Hi everyone!</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">It's been a long time since my last post on this list - happy to be back ;-)</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">As a long time user of jdom, I'm currently struggling with an issue that I don't think I can find a workaround for. Check out the following source (easy and simple):</FONT></P>

<P><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">public</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">class</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> CDATABug {</FONT>
</P>

<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">public</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">static</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">void</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> main(String[] args) {</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; Document doc =</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Document();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;</FONT> 

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; Element root =</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Element(</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;my_root&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; root.addContent(</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Element(</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;my_nested&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">).addContent(</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> CDATA(</FONT><FONT COLOR="#2A00FF" SIZE=2 FACE="Courier New">&quot;&quot;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">)));</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;</FONT> 

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; doc.setRootElement(root);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;</FONT> 

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; Format format = Format.<I>getRawFormat</I>();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; format.setTextMode(TextMode.</FONT><I><FONT COLOR="#0000C0" SIZE=2 FACE="Courier New">PRESERVE</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;</FONT> 

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; XMLOutputter putter =</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> XMLOutputter();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; putter.setFormat(format);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;</FONT> 

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">try</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> {</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putter.output(doc, System.</FONT><I><FONT COLOR="#0000C0" SIZE=2 FACE="Courier New">out</FONT></I><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; }</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">catch</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> (IOException e) {</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp;&nbsp;&nbsp; }</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&nbsp; }</FONT>
</P>

<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">}</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">IMHO, the expected output would be:</FONT>
</P>

<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&lt;my_root&gt;&lt;my_nested&gt;&lt;![CDATA[]]&gt;&lt;/my_nested&gt;&lt;/my_root&gt;</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">The output I get instead is (CDATA section completely omitted):</FONT>
</P>

<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</FONT>

<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&lt;my_root&gt;&lt;my_nested</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&gt;</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">&lt;/my_nested&gt;&lt;/my_root&gt;</FONT>
</P>
<BR>

<P><FONT SIZE=2 FACE="Arial">Is this really the behaviour that one should expect given that I explicitly ask XMLOutputter to preserve all of my text? I'd argue that if I explicitly do that and additionally use a CDATA object instead of plain text, I should be seeing the CDATA section with empty content.</FONT></P>

<P><FONT SIZE=2 FACE="Arial">Could you give me a heads-up? There's no way around outputting the CDATA section as a client requires this behaviour and there's probably nothing I can do about them changing their specs. They explicitly asked for an empty CDATA section instead of an element with empty text content ..</FONT></P>
<BR>

<P><FONT SIZE=2 FACE="Arial">Thanks for your help!</FONT>
</P>

<P><FONT SIZE=2 FACE="Arial">Ben</FONT>
</P>
<BR>

</BODY>
</HTML>