Losing CDATA when parsing a String to XML
843834Aug 19 2008 — edited Aug 19 2008Hi,
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>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
<![CDATA[" and ends with "]]>
</tr>
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.