Android Utililty Methods XML Element Child Get

List of utility methods to do XML Element Child Get

Description

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

Method

ElementfindChild(Element parent, String tagName)
Returns the child element with the specified tagName for the specified parent element.
if (parent == null || tagName == null)
    throw new NullPointerException("Parent or tagname were null! "
            + "parent = " + parent + "; tagName = " + tagName);
NodeList nodes = parent.getChildNodes();
Node node;
int len = nodes.getLength();
for (int i = 0; i < len; i++) {
    node = nodes.item(i);
...
ElementfindChildElement(Element parent, String name)
find Child Element
if (parent == null) {
    return null;
org.w3c.dom.Node ret = parent.getFirstChild();
while (ret != null
        && (!(ret instanceof Element) || !ret.getNodeName().equals(
                name))) {
    ret = ret.getNextSibling();
...
ElementfindChildElementWithAttribute(Element parent, String name, String attribute, String value)
find Child Element With Attribute
if (parent == null) {
    return null;
org.w3c.dom.Node ret = parent.getFirstChild();
while (ret != null
        && (!(ret instanceof Element)
                || !ret.getNodeName().equals(name)
                || ((Element) ret).getAttribute(attribute) == null || !((Element) ret)
...
ListfindChildren(Element parent, String tagName)
Returns the children elements with the specified tagName for the specified parent element.
if (parent == null || tagName == null)
    throw new NullPointerException("Parent or tagname were null! "
            + "parent = " + parent + "; tagName = " + tagName);
List<Element> result = new ArrayList<Element>();
NodeList nodes = parent.getChildNodes();
Node node;
int len = nodes.getLength();
for (int i = 0; i < len; i++) {
...
ElementfindFirstChildElement(Element parent)
find First Child Element
org.w3c.dom.Node ret = parent.getFirstChild();
while (ret != null && (!(ret instanceof Element))) {
    ret = ret.getNextSibling();
return (Element) ret;
ElementfirstChildWithName(Element element, String name)
first Child With Name
NodeList list = element.getChildNodes();
final int length = list.getLength();
for (int i = 0; i < length; ++i) {
    Node n = list.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE
            && n.getNodeName().equals(name))
        return (Element) n;
return null;
ElementgetChild(Element element, String name)
Get the first child element with the given name.
return (Element) element.getElementsByTagName(name).item(0);
NodegetChildByType(Element element, short nodeType)
Returns first of the element's child nodes that is of type nodeType.
if (element == null)
    return null;
NodeList nodes = element.getChildNodes();
if (nodes == null || nodes.getLength() < 1)
    return null;
Node node;
String data;
for (int i = 0; i < nodes.getLength(); i++) {
...
ElementgetChildElementByName(Element parent, String name)
get Child Element By Name
List<Element> children = getChildElementsByName(parent, name);
if (children.size() == 0) {
    return null;
if (children.size() > 1) {
    throw new RuntimeException("Unexpected number of '" + name
            + "' elements " + children.size());
return children.get(0);
StringgetChildValue(Element element, String name)
Get the value of the fist child element with the given name.
return getValue(getChild(element, name));