Java XML Element to String getStringValue(final Element element)

Here you can find the source of getStringValue(final Element element)

Description

Get element node string value.

License

Apache License

Parameter

Parameter Description
element element to get string value for

Return

concatenated text node descendant values

Declaration

public static String getStringValue(final Element element) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.*;

public class Main {
    /**//from   w  ww  .  j  a va2 s  . c om
     * Get element node string value.
     * 
     * @param element element to get string value for
     * @return concatenated text node descendant values
     */
    public static String getStringValue(final Element element) {
        final StringBuilder buf = new StringBuilder();
        final NodeList children = element.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            final Node n = children.item(i);
            switch (n.getNodeType()) {
            case Node.TEXT_NODE:
                buf.append(n.getNodeValue());
                break;
            case Node.ELEMENT_NODE:
                buf.append(getStringValue((Element) n));
                break;
            }
        }
        return buf.toString();
    }
}

Related

  1. getStringRepresentation(Element element)
  2. getStringValue(Element el)
  3. getStringValue(Element ele, String tagName)
  4. getStringValue(Element element, String tagName)
  5. getStringValue(Element from)
  6. getStringValueByTagName(Element element, String tagName)
  7. getStringValueOfElement(Element elem)
  8. getStringValues(Element from, String elementName)
  9. getXmlString(Element node)