get Child XML Element Text - Android XML

Android examples for XML:XML Element

Description

get Child XML Element Text

Demo Code


//package com.java2s;
import org.w3c.dom.Node;

public class Main {
    public static String getChildElementText(Node element,
            String childNodeName) {
        Node child = getChildElement(element, childNodeName);

        if (child != null) {
            return child.getTextContent();
        }//from w ww .ja v  a  2  s.  c o  m

        return null;
    }

    public static Node getChildElement(Node element, String childNodeName) {
        for (int i = 0; i < element.getChildNodes().getLength(); i++) {
            Node child = element.getChildNodes().item(i);
            if (child.getNodeName().equals(childNodeName)) {
                return child;
            }
        }

        return null;
    }
}

Related Tutorials