Android XML Element Value Get getValue(Element item, String str)

Here you can find the source of getValue(Element item, String str)

Description

get Value

Declaration

public static String getValue(Element item, String str) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getValue(Element item, String str) {
        NodeList n = item.getElementsByTagName(str);
        return getElementValue(n.item(0));
    }/*from   ww w.j  a  v  a 2  s.co m*/

    public static String getElementValue(Node elem) {
        Node child;
        if (elem != null) {
            if (elem.hasChildNodes()) {
                for (child = elem.getFirstChild(); child != null; child = child
                        .getNextSibling()) {
                    if (child.getNodeType() == Node.TEXT_NODE) {
                        return child.getNodeValue();
                    }
                }
            }
        }
        return "";
    }
}

Related

  1. getTextNode(Element element)
  2. getTextTrim(Element elto)
  3. getTextTrim(Element elto)
  4. getValue(Element element)
  5. getValue(Element element, String elementName)
  6. getStringValue(String tag, Element element)
  7. getCData(Element element)
  8. getContent(Element xmlElement)
  9. getElementText(Element element)