Here you can find the source of getTextContent(Element element)
Parameter | Description |
---|---|
element | the element to check for text content |
Parameter | Description |
---|---|
DOMException | an exception |
static String getTextContent(Element element) throws DOMException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w . ja va 2 s . c o m * IBM Corporation - initial API and implementation *******************************************************************************/ import org.w3c.dom.*; public class Main { /** * Returns the value of any text nodes stored as children of the given element * @param element the element to check for text content * @return string containing text content of element or empty string * @throws DOMException */ static String getTextContent(Element element) throws DOMException { NodeList children = element.getChildNodes(); StringBuffer result = new StringBuffer(); for (int i = 0; i < children.getLength(); ++i) { Node currentNode = children.item(i); if (currentNode.getNodeType() == Node.TEXT_NODE) { result.append(currentNode.getNodeValue()); } } return result.toString(); } }