Java XML Element Get Value getText(Element aElement)

Here you can find the source of getText(Element aElement)

Description

Returns a concatenation of all of the text nodes and CDATA nodes that are immediate children of this element.

License

Open Source License

Parameter

Parameter Description
aElement a parameter

Declaration

public static String getText(Element aElement) 

Method Source Code

//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**/* ww w.  j  a  v  a  2s .  co m*/
     * Returns a concatenation of all of the text nodes and CDATA nodes that are
     * immediate children of this element.
     *
     * @param aElement
     */
    public static String getText(Element aElement) {
        // short return if no element has been passed
        if (aElement == null)
            return null;

        StringBuilder buffer = new StringBuilder();

        NodeList nl = aElement.getChildNodes();
        for (int i = 0; nl.item(i) != null; i++) {
            Node child = nl.item(i);
            switch (child.getNodeType()) {
            case Node.CDATA_SECTION_NODE:
            case Node.TEXT_NODE:
                buffer.append(child.getNodeValue());
            }
        }

        return buffer.toString();
    }
}

Related

  1. getTagText(Element ele)
  2. getTagValue(Element e)
  3. getTagValue(Element e, String tag)
  4. getTagValue(Element element, String tagName)
  5. getTagValue(Element element, String tagName)
  6. getText(Element config)
  7. getText(Element config)
  8. getText(Element e)
  9. getText(Element el)