Java XML Element Get Value getText(Element config)

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

Description

returns the first text child within the node.

License

Open Source License

Declaration

public static String getText(Element config) 

Method Source Code

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

import org.w3c.dom.Element;

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

public class Main {
    /**//  ww w  . j  a v  a  2 s. c o m
     * returns the first text child within the node.
     */
    public static String getText(Element config) {
        if (config == null) {
            throw new IllegalArgumentException("config cannot be null");
        }
        NodeList children = config.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            if (children.item(i) instanceof Text) {
                return children.item(i).getNodeValue();
            }
        }
        // nothing found, return null
        return null;
    }
}

Related

  1. getTagValue(Element e)
  2. getTagValue(Element e, String tag)
  3. getTagValue(Element element, String tagName)
  4. getTagValue(Element element, String tagName)
  5. getText(Element aElement)
  6. getText(Element config)
  7. getText(Element e)
  8. getText(Element el)
  9. getText(Element elem)