Android Utililty Methods XML Element Value Get

List of utility methods to do XML Element Value Get

Description

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

Method

StringgetNodeValue(Element node)
This will get the text value of an element.
String retval = "";
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
    Node next = children.item(i);
    if (next instanceof Text) {
        retval = next.getNodeValue();
return retval;
StringgetNodeValue(Element node)
This will get the text value of an element.
StringBuilder sb = new StringBuilder();
NodeList children = node.getChildNodes();
int numNodes = children.getLength();
for (int i = 0; i < numNodes; i++) {
    Node next = children.item(i);
    if (next instanceof Text) {
        sb.append(next.getNodeValue());
return sb.toString();
StringgetText(Element parentNode)
Extracts the String content of a TXT element.
Text text = getTextNode(parentNode);
return (text == null) ? null : text.getData();
TextgetTextNode(Element element)
Returns element's TEXT child node (if it has one).
return (Text) getChildByType(element, Node.TEXT_NODE);
StringgetTextTrim(Element elto)
get Text Trim
StringBuffer content = new StringBuffer();
NodeList contentE = elto.getChildNodes();
int i = 0;
while (contentE.item(i) != null
        && (contentE.item(i).getNodeType() == Node.TEXT_NODE || contentE
                .item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
    content.append(((Text) contentE.item(i)).getNodeValue());
    i++;
...
StringgetTextTrim(Element elto)
get Text Trim
StringBuffer content = new StringBuffer();
NodeList contentE = elto.getChildNodes();
int i = 0;
while (contentE.item(i) != null
        && (contentE.item(i).getNodeType() == Node.TEXT_NODE || contentE
                .item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
    content.append(((Text) contentE.item(i)).getNodeValue());
    i++;
...
StringgetValue(Element element)
Get the text value for the specified element.
if (element != null) {
    Node dataNode = element.getFirstChild();
    if (dataNode != null) {
        return ((Text) dataNode).getData();
return null;
StringgetValue(Element element, String elementName)
get Value
NodeList elements = element.getElementsByTagName(elementName);
if (1 != elements.getLength()) {
    throw new IllegalStateException(
            "TODO: handle when elements does not contain exactly one item.elementName="
                    + elementName);
Node elementNode = elements.item(0);
NodeList children = elementNode.getChildNodes();
...
StringgetValue(Element item, String str)
get Value
NodeList n = item.getElementsByTagName(str);
return getElementValue(n.item(0));
StringgetStringValue(String tag, Element element)
get String Value
NodeList nodes = element.getElementsByTagName(tag).item(0)
        .getChildNodes();
Node node = (Node) nodes.item(0);
return node.getNodeValue();