Example usage for org.w3c.dom Element getTextContent

List of usage examples for org.w3c.dom Element getTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element getTextContent.

Prototype

public String getTextContent() throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:Main.java

public static String contentStringGet(Element e, String defaultValue) {
    if (e == null) {
        return defaultValue;
    } else {//from   w  w w  .ja  va  2  s  .com
        return e.getTextContent();
    }
}

From source file:Main.java

public static int contentIntGet(Element e, int defaultInt) {
    if (e == null) {
        return defaultInt;
    } else {// w  w  w  .ja  v  a2  s  . c  om
        String text = e.getTextContent();
        return Integer.parseInt(text);
    }
}

From source file:Main.java

/**
 * Retrieves the text content of the specified sub element for the given element.
 *
 * @param   elem     The element whose subelement text contents is to be retrieved.
 * @param   tagName  Name of the subelement.
 * @pre     elem != null && tagName != null && !tagName.equals("")
 * @return  The text contents of the specified sub element, or null if the subelement
 *          does not exist.//from   w w  w .j  ava2 s. c  o m
 */
public static String getSubElementContents(Element elem, String tagName) {
    Element child = getChildElement(elem, tagName);
    if (child != null) {
        return child.getTextContent();
    } else {
        return null;
    }
}

From source file:Main.java

public static long contentLongGet(Element e, long defaultLong) {
    if (e == null) {
        return defaultLong;
    } else {/*from   w  ww.  jav  a2s .c o m*/
        String text = e.getTextContent();
        return Long.parseLong(text);
    }
}

From source file:Main.java

public static String getElementValue(Element parent, String tagName) {
    String value = null;/*from   w w  w  .j  a va 2  s .  c o m*/

    Element element = getChildElement(parent, tagName);
    if (element != null) {
        value = element.getTextContent();
    }

    return value;
}

From source file:Main.java

public static String getText(Element element, String tagName, String def) {
    Element child = getChild(element, tagName);
    String text = null;//ww  w . jav  a2  s.  c  o m
    if (child != null)
        text = child.getTextContent();
    if (text == null)
        text = def;
    return text;
}

From source file:Main.java

public static double contentDoubleGet(Element e, double defaultDouble) {
    if (e == null) {
        return defaultDouble;
    } else {/*www  .  j a  va2  s . c o  m*/
        String text = e.getTextContent();
        return Double.parseDouble(text);
    }
}

From source file:Main.java

/**
 * Return the text content of the first child of the element with the specified tag
 * @param element - the element under which to look for the child element
 * @param tag - the tag name for the child
 * @return The text content (or null if there was no child of that name).
 *//*from   ww w . j ava 2s.  c  om*/
public static String childText(Element element, String tag) {
    Element child = child(element, tag);
    return child != null ? child.getTextContent() : null;
}

From source file:Main.java

public static String getAttribute(Element elem, String attr, String def) {
    NodeList nlist = elem.getElementsByTagName("attribute");
    String value = null;/*from  ww  w.j  a  v a 2s . co m*/

    for (int i = 0; i < nlist.getLength(); i++) {
        Element node = (Element) nlist.item(i);
        if (attr.equals(node.getAttribute("name"))) {
            value = node.getTextContent();
            break;
        }
    }

    if (value == null) {
        value = def;
    }
    return value;
}

From source file:Main.java

public static String getElementValue(Element parent, String childName, String childNamespace) {
    Element child = getChildElement(parent, childName, childNamespace);
    if (child == null)
        return null;

    return child.getTextContent();
}