Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Losing CDATA when parsing a String to XML

843834Aug 19 2008 — edited Aug 19 2008
Hi,
I'm using the following code to parse a String to XML -
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
Document document = null;

try
{
DocumentBuilder builder = factory.newDocumentBuilder();

document = builder.parse(new InputSource(new StringReader(xmlString)));
}
catch (Exception ex)
{
ex.printStackTrace();
}

But if I have a CDATA section within the String (xmlString variable), I lose it.Example: If I have the following as input -
<tr>&#xD;
<td><xsl:value-of select="title"/></td>&#xD;
<td><xsl:value-of select="artist"/></td>&#xD;
<![CDATA[" and ends with "]]>&#xD;
</tr>&#xD;

After parsing it I get back

<tr>
<td>
<xsl:value-of select="title"/>
</td>
<td>
<xsl:value-of select="artist"/>
</td>
" and ends with "
</tr>

I'm not sure why the Cdata section is removed. Will appreciate any help. Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2008
Added on Aug 19 2008
1 comment
324 views