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

/**
 * Method for handling deserialization of String objects.
 * @author Tristan Bepler//from  w w w  .  j ava2s. com
 */
private static String readSpecialCaseObjectIsString(Class<?> clazz, Element cur) {
    if (clazz == String.class) {
        return cur.getTextContent();
    }
    return null;
}

From source file:Main.java

/**
 * Die getValueFromXMLTag(String tag) Methode sorgt dafuer das anhand des tags der value zurueck gegeben wird.
 * @param tag//from w w w. ja va 2s. c o  m
 * @return value
 */
public static String getValueFromXMLTag(String tag) {
    NodeList ndList = document.getElementsByTagName(tag);
    String value = null;
    for (int i = 0; i < ndList.getLength(); i++) {
        Element element = (Element) ndList.item(i);
        value = element.getTextContent();
    }
    return value;
}

From source file:Main.java

public static List<String> getChildTextsByTagName(Element element, String tagName) {
    List<Element> elements = getChildElementsByTagName(element, tagName);
    List<String> list = new ArrayList<String>();
    for (Element e : elements) {
        String textValue = e.getTextContent().trim();
        if (textValue.length() != 0) {
            list.add(textValue);/* w  ww .  j a  va  2  s.  c  om*/
        }
    }
    return list;
}

From source file:Main.java

public static String getChildElementContent(Element el, String tagName) {
    Element el2 = getChildElement(el, tagName);
    return el2 == null ? "" : el2.getTextContent();
}

From source file:Main.java

public static String elementText(Element element, String tagName) {
    Element child = getElement(element, tagName);
    return child == null ? null : child.getTextContent();
}

From source file:Main.java

/**
 * Extracts the content of the element named <var>name</var> with the namespace
 * <var>elementNS</var> that is a descentant of the element
 * <var>message</var>. This method returns null if the named elemens is not
 * a child of <var>message</var> or if <var>message</var> contains more than
 * one element named <var>name</var>
 * /*from  ww w  .  j  av  a  2 s.co m*/
 * @param message
 *            Source Document that contains the element named
 *            <var>name</var>
 * @param elementNS
 *            Namespace of the element named <var>name</var>
 * @param name
 *            Name of the element to be extracted
 * @return Element named <var>name</var>, <br>
 *         or null if <var>message</var> contains zero or more than one
 *         element named <var>name</var>
 */
public static String extractElementText(Element message, String elementNS, String name, boolean strict) {
    NodeList list = message.getElementsByTagNameNS(elementNS, name);
    if (list == null || list.getLength() == 0 || (strict && list.getLength() != 1))
        return null;
    Element element = (Element) list.item(0);
    return element.getTextContent();
}

From source file:Main.java

public static String readStringElement(Element parentElement, String name, int index) {
    Element element = (Element) parentElement.getElementsByTagName(name).item(index);
    String text = element.getTextContent();
    if (text == "null") {
        text = null;/*from  w w w . j  a v a 2s .co m*/
    }
    return text;
}

From source file:Main.java

public static String elementText(Element element, String tagName, String defaultValue) {
    Element child = getElement(element, tagName);
    return child == null ? defaultValue : child.getTextContent();
}

From source file:Main.java

public static String getElementValue(Element parent, String tagName) {
    Element element = getElement(parent, tagName);
    return element != null ? element.getTextContent() : null;
}

From source file:Main.java

public static List<String> getByName(String name, Element node) {
    List<String> r = new ArrayList<String>();
    List<Element> l = getRealChilds(node);
    for (Element n : l) {
        if (n.getNodeName().equals(name)) {
            r.add(n.getTextContent());
        }//from ww w . java  2  s.  c  om
    }
    return r;
}