I am trying to retrieve CDATA value in JDOM2 using getText() but I only get the following -
<![CDATA[ ]]>
My XML looks like below
<ROOT>
<CHILD>
<P><![CDATA[<ROOT><ELEMENT>SOMECONTENT</ELEMENT></ROOT>]]></P>
</CHILD>
</ROOT>
the CDATA contains XML content which I need as string to store it elsewejhere Code(snippet) looks like below
XPathFactory xpfac = XPathFactory.instance();
XPathExpression<Element> xElements = xpfac.compile(sXpath,Filters.element(),null,Namespace.getNamespace("myns", "http://www.namespace.com/ns"));
List<Element> elements = xElements.evaluate(doc);
for (Element xElem : elements) {
if(!isCDATA)
{
sRetval=xElem.getValue();
}
else
{
sRetval=xElem.getText();
}
return sRetval;
}
getValue()
works fine whereas getText()
returns only <![CDATA[ ]]>
of course my XPAHT looks like this
//ROOT/CHILD/P
Any idea how I could get the content of CDATA?
Edit: If I repalce <P><![CDATA[ SOMECONTENT]]></P>
I am getting "SOMECONTENT"..So I am unable to get the XML content from CDATA
` tag.
– millimoose Apr 14 '13 at 19:47