Java XML Element Text getElementText(Element element)

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

Description

Return the contained text within an Element.

License

Open Source License

Declaration

public final static String getElementText(Element element) 

Method Source Code

//package com.java2s;
import org.w3c.dom.*;

public class Main {
    /**//from   w ww .  ja  v a2s  .  c  o m
     * Return the contained text within an Element. Returns null if no text found.
     */
    public final static String getElementText(Element element) {
        NodeList nl = element.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. getElementText(Element elem, boolean mandatory)
  2. getElementText(Element elem, String name)
  3. getElementText(Element element)
  4. getElementText(Element element)
  5. getElementText(Element element)
  6. getElementText(Element element)
  7. getElementText(Element element)
  8. getElementText(Element element)
  9. getElementText(Element element)