tags:

views:

1432

answers:

2

This is a followup question of How to encode characters from Oracle to Xml?

In my environment here I use Java to serialize the result set to xml. I have no access to the output stream itself, only to a org.xml.sax.ContentHandler.

When I try to output characters in a CDATA Section:

It happens basically like this:

xmlHandler.startElement(uri, lname, "column", attributes);
String chars = "<![CDATA["+rs.getString(i)+"]]>";
xmlHandler.characters(chars.toCharArray(), 0, chars.length());
xmlHandler.endElement(uri, lname, "column");

I get this:

<column>&lt;![CDATA[33665]]&gt;</column>

But I want this:

<column><![CDATA[33665]]></column>

So how can I output a CDATA section with a Sax ContentHandler?

+2  A: 
Josh
thanks for the input. I will look into it.
Andre Bossard
+1  A: 

You should use startCDATA() and endCData() as delimiters, i.e.

xmlHandler.startElement(uri, lname, "column", attributes);
xmlHandler.startCDATA();
String chars = rs.getString(i);
xmlHandler.characters(chars.toCharArray(), 0, chars.length());
xmlHandler.endCDATA();
xmlHandler.endElement(uri, lname, "column");
Dani