Java XML Element Get Value getTextElementValue(Element ele)

Here you can find the source of getTextElementValue(Element ele)

Description

get Text Element Value

License

Open Source License

Parameter

Parameter Description
ele a parameter

Return

the element value of the TEXT_NODE children of element concat'd together

Declaration

public static String getTextElementValue(Element ele) 

Method Source Code

//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();
    }
}

Related

  1. getTextContentFromFirstElementByTagName(Element element, String tagName)
  2. getTextContentOfElement(Element elem, String tagName, boolean required)
  3. getTextContentOfElements(Element elem, String tagName)
  4. getTextContents(Element e)
  5. getTextData(Element element)
  6. getTextFromFirstSubEleByName(Element element, String tagName)
  7. getTextFromTag(Element current, String tag)
  8. getTextList(Element elem, String name)
  9. getTextOfElement(Element e)