Java XML Element Text getElementText(Element n)

Here you can find the source of getElementText(Element n)

Description

get Element Text

License

Apache License

Declaration

public static String getElementText(Element n) 

Method Source Code

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

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getElementText(Element n) {
        NodeList childNodes = n.getChildNodes();
        String result = new String();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            if (node.getNodeType() == Node.TEXT_NODE) {
                result += node.getNodeValue();
            }//from  w w  w . ja  v  a  2s  .  c  o m
        }
        return result;
    }
}

Related

  1. getElementText(Element element)
  2. getElementText(Element element, String tagName, String namespace)
  3. getElementText(Element elm)
  4. getElementText(Element elm)
  5. getElementText(Element elm)
  6. getElementText(Element namedElement)
  7. getElementText(Element root, String tagname)
  8. getElementText(final Element element)
  9. getElementTextByTagName(Element n, String elementName)