Java XML Element Get Value getTextContent(Element e)

Here you can find the source of getTextContent(Element e)

Description

get Text Content

License

Open Source License

Parameter

Parameter Description
e a parameter

Declaration

public static String getTextContent(Element e) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from www .j a v  a  2  s . c om*/
     * 
     * @param e
     * @return
     */
    public static String getTextContent(Element e) {
        String ret = null;
        boolean found = false;
        StringBuffer buffer = new StringBuffer();
        NodeList childList = e.getChildNodes();
        for (int i = 0; i < childList.getLength(); i++) {
            Node child = childList.item(i);
            if (child.getNodeType() != Node.TEXT_NODE)
                continue; // skip non-text nodes
            buffer.append(child.getNodeValue());
            found = true;
        }
        if (found) {
            ret = buffer.toString();
        }
        return ret;
    }
}

Related

  1. getText(Element node)
  2. getText(final Element el)
  3. getText(final Element element)
  4. getText(final Element element, final StringBuilder sbuf, final boolean decend)
  5. getText(final Element tag)
  6. getTextContent(Element e, String name)
  7. getTextContent(Element el)
  8. getTextContent(Element ele)
  9. getTextContent(Element element)