Here you can find the source of getText(Element e)
Parameter | Description |
---|---|
e | the element. |
public static String getText(Element e)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from ww w . j a va 2 s .c o m*/ * Gets the text value of the given element. * * @param e the element. * @return the text contents of the given element.s */ public static String getText(Element e) { StringBuilder sb = null; if (e != null) { NodeList children = e.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); switch (node.getNodeType()) { case Node.TEXT_NODE: case Node.CDATA_SECTION_NODE: if (sb == null) { sb = new StringBuilder(); } sb.append(node.getNodeValue()); break; } } } return (sb != null) ? sb.toString() : null; } }