Here you can find the source of getText(Element elem)
Parameter | Description |
---|---|
elem | Element |
public static final String getText(Element elem)
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**//from w w w. ja v a 2s. c o m * Get Text Content of the given element. * * @param elem * Element * * @return Trimmed text content of the element. */ public static final String getText(Element elem) { if (elem != null) { NodeList childNodes = elem.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) { return trim(childNodes.item(i).getNodeValue()); } } } return null; } private static String trim(String input) { if (input == null) { return input; } return input.trim(); } }