Wednesday, December 03, 2003

Getting Text from an XML CDATA_SECTION_NODE in Java.

Here is a code snippet showing how to get text from a CDATA node in XML.
NodeList nodeList = node.getChildNodes();
if (nodeList != null) {
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node child = nodeList.item(i);
        if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
	CDATASection cdata = (CDATASection)child;
	System.out.println('The CDATA has text: [" + cdata.getData() + "]");
        }
    }
}