Here you can find the source of getTextElementValue(Element ele)
Parameter | Description |
---|---|
ele | a parameter |
public static String getTextElementValue(Element ele)
//package com.java2s; /******************************************************************************* * Copyright (c) 2006 Sybase, Inc. 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://w w w. j ava 2s. com * Sybase, Inc. - initial API and implementation *******************************************************************************/ import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /** * @param ele * @return the element value of the TEXT_NODE children of element * concat'd together */ public static String getTextElementValue(Element ele) { StringBuffer buffer = new StringBuffer(); Node node = ele.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.TEXT_NODE) { buffer.append(node.getNodeValue()); } else if (node.getNodeType() == Node.CDATA_SECTION_NODE) { buffer.append(node.getNodeValue()); } node = node.getNextSibling(); } return buffer.toString(); } }