Java XML Element Get Value getText(Element node)

Here you can find the source of getText(Element node)

Description

get Text

License

Open Source License

Declaration

public static String getText(Element node) 

Method Source Code

//package com.java2s;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getText(Element node) {
        StringBuffer sb = new StringBuffer();
        NodeList list = node.getChildNodes();

        for (int i = 0; i < list.getLength(); i++) {
            Node child = list.item(i);

            switch (child.getNodeType()) {
            case Node.CDATA_SECTION_NODE:
            case Node.TEXT_NODE:
                sb.append(child.getNodeValue());
            }//w ww  .  ja  v a 2  s.  c  om
        }

        return sb.toString();
    }
}

Related

  1. getText(Element element)
  2. getText(Element element)
  3. getText(Element element)
  4. getText(Element element, String name)
  5. getText(Element element, String tagName)
  6. getText(final Element el)
  7. getText(final Element element)
  8. getText(final Element element, final StringBuilder sbuf, final boolean decend)
  9. getText(final Element tag)