Java XML Node Text Value getNodeText(final Node node)

Here you can find the source of getNodeText(final Node node)

Description

Return the contained text within an Element.

License

Open Source License

Declaration

public static String getNodeText(final Node node) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*  ww  w .  j a v a 2  s.  c o  m*/
     * Return the contained text within an Element. Returns null if no text found.
     */
    public static String getNodeText(final Node node) {
        NodeList nl = node.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node c = nl.item(i);
            if (c instanceof Text)
                return ((Text) c).getData();
        }
        return null;
    }
}

Related

  1. getFirstSubElementsInnerText(Node element, String subElementName)
  2. getInnerXmlText(Node xmlNode)
  3. getNamedItemText(NamedNodeMap map, String name)
  4. getNamespaceURIFromPrefix(Node context, String prefix)
  5. getNamespaceURIFromPrefix(Node context, String prefix)
  6. getNodeText(Node node)
  7. getNodeText(Node node)
  8. getNodeText(Node node)
  9. getNodeText(Node node)