Here you can find the source of getText(final Element element, final StringBuilder sbuf, final boolean decend)
Parameter | Description |
---|---|
element | The element. |
sbuf | The buffer to append to. |
decend | Whether to descend into child elements. |
public static void getText(final Element element, final StringBuilder sbuf, final boolean decend)
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**/* w ww . j a v a 2 s . c o m*/ * Get the direct text content of an element. * * @param element * The element. * * @return The contained text. */ public static String getText(final Element element) { final StringBuilder sbuf = new StringBuilder(); getText(element, sbuf, false); return sbuf.toString(); } /** * Get the text content of an element. * * @param element * The element. * @param sbuf * The buffer to append to. * @param decend * Whether to descend into child elements. */ public static void getText(final Element element, final StringBuilder sbuf, final boolean decend) { Node node = element.getFirstChild(); while (node != null) { switch (node.getNodeType()) { case Node.TEXT_NODE: sbuf.append(node.getNodeValue()); break; case Node.ELEMENT_NODE: if (decend) { getText((Element) node, sbuf, decend); } break; } node = node.getNextSibling(); } } }