Java XML CDATA Get getElementCDATAByTagName(Element current, String name, String namespace)

Here you can find the source of getElementCDATAByTagName(Element current, String name, String namespace)

Description

get Element CDATA By Tag Name

License

Apache License

Declaration

public static String getElementCDATAByTagName(Element current, String name, String namespace) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getElementCDATAByTagName(Element current, String name) {

        return getElementCDATAByTagName(current, name, null);
    }/*from   ww w . ja  v a  2  s . c  o  m*/

    public static String getElementCDATAByTagName(Element current, String name, String namespace) {

        Element e = getElementByTagName(current, name, namespace);

        if (e == null)
            return null;

        Node child = e.getFirstChild();

        if (child == null)
            return null;

        return child.getNodeValue();

    }

    public static Element getElementByTagName(Element current, String name) {
        return getElementByTagName(current, name, null);
    }

    public static Element getElementByTagName(Element current, String name, String namespace) {

        NodeList elements = null;

        if (namespace == null)
            elements = current.getElementsByTagName(name);
        else
            elements = current.getElementsByTagNameNS(namespace, name);

        if (elements == null)
            return null;

        if (elements.getLength() != 1)
            return null;

        return (Element) elements.item(0);

    }
}

Related

  1. getCDataNode(Element element)
  2. getCDataValue(Node node, String tag)
  3. getChildCdata(Node element, String name)
  4. getChildCharacterData(Element parentEl)
  5. getChildCharacterData(Element parentEl)