Java Utililty Methods XML CDATA Get

List of utility methods to do XML CDATA Get

Description

The list of methods to do XML CDATA Get are organized into topic(s).

Method

StringgetCDATA(Element elem)
get CDATA
return getCDATA(elem, true);
StringgetCdata(Element elem)
Extracts the first CDATA child from the given org.w3c.dom.Element .
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;
StringgetCData(Element element)
Extract the CDATA content of the specified element.
CDATASection text = getCDataNode(element);
if (text != null)
    return text.getData().trim();
else
    return null;
CDATASectiongetCDataNode(Element element)
Returns element's CDATA child node (if it has one).
return (CDATASection) getChildByType(element, Node.CDATA_SECTION_NODE);
StringgetCDataValue(Node node, String tag)
Returns the CDATA value of the subnode of specified node with the specified tag.
String ret = null;
Node child = getChildNode(node, tag);
if (child != null) {
    NodeList grandchildren = child.getChildNodes();
    Node grandchild = grandchildren.item(0);
    if (grandchild != null) {
        ret = grandchild.getNodeValue();
return ret;
StringgetChildCdata(Node element, String name)
get Child Cdata
for (Node node : iter(element.getChildNodes())) {
    if (node.getNodeName().equals(name)) {
        StringBuilder buf = new StringBuilder();
        textRecurse(node, buf);
        return buf.toString();
return null;
...
StringgetChildCharacterData(Element parentEl)
Concat all the text and cdata node children of this elem and return the resulting text.
if (parentEl == null) {
    return null;
Node tempNode = parentEl.getFirstChild();
StringBuffer strBuf = new StringBuffer();
CharacterData charData;
while (tempNode != null) {
    switch (tempNode.getNodeType()) {
...
StringgetChildCharacterData(Element parentEl)
Concat all the text and cdata node children of this elem and return the resulting text.
if (parentEl == null) {
    return null;
Node tempNode = parentEl.getFirstChild();
StringBuffer strBuf = new StringBuffer();
CharacterData charData;
while (tempNode != null) {
    switch (tempNode.getNodeType()) {
...
StringgetElementCDATAByTagName(Element current, String name, String namespace)
get Element CDATA By Tag Name
Element e = getElementByTagName(current, name, namespace);
if (e == null)
    return null;
Node child = e.getFirstChild();
if (child == null)
    return null;
return child.getNodeValue();