Java XML Element Get Value getTagText(Element ele)

Here you can find the source of getTagText(Element ele)

Description

Scans the tag's children and returns the first text element found

License

Open Source License

Declaration

public static String getTagText(Element ele) 

Method Source Code


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

public class Main {
    /**//from w  w w . j a  v a  2  s  .com
     * Scans the tag's children and returns the first text element found
     */
    public static String getTagText(Element ele) {
        NodeList nl = ele.getChildNodes();
        int size = nl.getLength();

        Node node = null;
        int i = 0;
        for (; i < size; i++) {
            node = nl.item(i);
            if (node instanceof Text)
                break;
        }
        if (i == size || node == null)
            return null;

        return ((Text) node).getData();
    }
}

Related

  1. getTagElement(Element node, String key)
  2. getTagLocalName(final Element element)
  3. getTagNameIgnorePrefix(Element element)
  4. getTagValue(Element e)
  5. getTagValue(Element e, String tag)
  6. getTagValue(Element element, String tagName)
  7. getTagValue(Element element, String tagName)