Java Utililty Methods XML Element Get Value

List of utility methods to do XML Element Get Value

Description

The list of methods to do XML Element Get Value are organized into topic(s).

Method

StringgetText(Element config)
returns the concatenation of all text children within the node.
if (config == null)
    return new String("");
NodeList children = config.getChildNodes();
Node node;
String out = "";
for (int i = 0; i < children.getLength(); i++) {
    node = children.item(i);
    if (node instanceof Text) {
...
StringgetText(Element e)
Gets the text value of the given element.
StringBuilder sb = null;
if (e != null) {
    NodeList children = e.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        switch (node.getNodeType()) {
        case Node.TEXT_NODE:
        case Node.CDATA_SECTION_NODE:
...
StringgetText(Element el)
get the text string in an element (eg interspersed between child elements), or "" if there is none or if the Element is null.
String res = "";
if (el != null)
    try {
        el.normalize(); 
        NodeList nodes = el.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++)
            if (nodes.item(i) instanceof Text) {
                Text text = (Text) nodes.item(i);
...
StringgetText(Element elem)
get Text
if (elem != null) {
    NodeList childNodes = elem.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) {
            return trim(childNodes.item(i).getNodeValue());
return null;
StringgetText(Element elem)
Extract the text in an element.
StringBuffer text = new StringBuffer();
NodeList l = elem.getChildNodes();
for (int i = 0; i < l.getLength(); i++) {
    Node n = l.item(i);
    if (n instanceof Text)
        text.append(((Text) n).getData());
    else if (n instanceof CDATASection)
        text.append(((CDATASection) n).getData());
...
StringgetText(Element elem)
get Text
StringBuffer sb = new StringBuffer(64);
NodeList nl = elem.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    Node n = nl.item(i);
    switch (n.getNodeType()) {
    case Node.TEXT_NODE:
        sb.append(((Text) n).getData());
        break;
...
StringgetText(Element elem)
Get Text Content of the given element.
if (elem != null) {
    NodeList childNodes = elem.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) {
            return trim(childNodes.item(i).getNodeValue());
return null;
StringgetText(Element elem, String ifnull)
get Text
String retVal = null;
Node node = elem.getFirstChild();
if (node != null) {
    if (node.getNodeType() == Node.TEXT_NODE) {
        retVal = ((Text) node).getData();
    } else {
        System.out.println("Invalid element type in getText().");
} else {
    retVal = ifnull;
return retVal;
StringgetText(Element elem, String name)
get Text
Element childElement = getFirstChildElement(elem, name);
if (childElement == null) {
    return "";
Node node = childElement.getFirstChild();
return node == null ? "" : node.getTextContent();
StringgetText(Element element)
get Text
StringBuilder buffer = new StringBuilder();
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    if (children.item(i) instanceof Text) {
        buffer.append(((Text) children.item(i)).getData());
return buffer.toString();
...