Java XML CData getCharacterData(Element el)

Here you can find the source of getCharacterData(Element el)

Description

Gets the character data corresponding to the given DOM element.

License

Open Source License

Declaration

public static String getCharacterData(Element el) 

Method Source Code

//package com.java2s;

import org.w3c.dom.*;

public class Main {
    /** Gets the character data corresponding to the given DOM element. */
    public static String getCharacterData(Element el) {
        Text text = getChildTextNode(el);
        return text == null ? null : text.getData();
    }//from w w  w  . ja v a  2 s. c  om

    /**
     * Gets the child text node containing character data
     * for the given DOM element.
     */
    public static Text getChildTextNode(Element el) {
        if (el == null)
            return null;
        NodeList list = el.getChildNodes();
        int size = list.getLength();
        for (int i = 0; i < size; i++) {
            Node node = list.item(i);
            if (!(node instanceof Text))
                continue;
            return (Text) node;
        }
        return null;
    }
}

Related

  1. createNewCDATAElement(Node elem, String tag, String value)
  2. getCharacterDataFromElement(Element e)
  3. getCharacterDataFromElement(Element e)
  4. getCharacterDataFromElement(Element e)
  5. getCharacterDataFromElementWithKey(final Element element, final String key)