Android XML Element Value Get getValue(Element element, String elementName)

Here you can find the source of getValue(Element element, String elementName)

Description

get Value

Declaration

public static String getValue(Element element, String elementName) 

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 element, String elementName) {
        NodeList elements = element.getElementsByTagName(elementName);
        if (1 != elements.getLength()) {
            throw new IllegalStateException(
                    "TODO: handle when elements does not contain exactly one item.elementName="
                            + elementName);
        }/*w  w  w  . j  ava 2  s.  c  o m*/
        Node elementNode = elements.item(0);
        NodeList children = elementNode.getChildNodes();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < children.getLength(); i++) {
            String value = children.item(i).getNodeValue();
            sb.append(value);
        }
        return sb.toString();
    }
}

Related

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