2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

12/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() + "]");
        }
    }
}


subscribe via RSS