Java tutorial
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import org.w3c.dom.CharacterData; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Extracts the first CDATA child from the given {@code org.w3c.dom.Element}. * * @param elem the parent Element * @return the String value of the CDATA section, or {@code null} if none * found */ public static String getCdata(Element elem) { NodeList nodes = elem.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.CDATA_SECTION_NODE) { CharacterData cdataNode = (CharacterData) node; return cdataNode.getData(); } } return null; } }