Android Utililty Methods XML Node Child Get

List of utility methods to do XML Node Child Get

Description

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

Method

StringgetChildTagValue(Node node, String tag)
get Child Tag Value
Element element = (Element) node;
NodeList childrenWithTag = element.getElementsByTagName(tag)
        .item(0).getChildNodes();
Node valueNode = (Node) childrenWithTag.item(0);
return valueNode.getNodeValue();
StringgetChildText(Node n)
get Child Text
StringBuffer str = new StringBuffer();
NodeList nl = n.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    Node c = nl.item(i);
    if (c.getNodeType() == Node.TEXT_NODE) {
        str.append(c.getNodeValue());
return str.toString();
ListgetChildren(Node node, String name)
get Children
List<Node> children = new ArrayList<Node>();
NodeList nodes = node.getChildNodes();
if (nodes != null && nodes.getLength() >= 1) {
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        if (name.equals(n.getNodeName())) {
            children.add(n);
return children;
ListgetChildren(Node node, String name)
get Children
List<Node> children = new ArrayList<Node>();
NodeList nodes = node.getChildNodes();
if (nodes != null && nodes.getLength() >= 1) {
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        if (name.equals(n.getNodeName())) {
            children.add(n);
return children;
ListgetChildren(Node node, String name)
get Children
List<Node> children = new ArrayList<Node>();
NodeList nodes = node.getChildNodes();
if (nodes != null && nodes.getLength() > 0) {
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.item(i);
        if (name.equals(n.getNodeName())) {
            children.add(n);
return children;
ListgetChildrenOfName(Node node, String name)
get Children Of Name
List<Node> res = new ArrayList<Node>();
NodeList childNodes = node.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
    Node item = childNodes.item(i);
    String localName = item.getNodeName();
    if (name.equals(localName)) {
        res.add(item);
return res;
NodegetFirstChild(Node node, String namespace, String name)
Return the first child of a node, based on name/namespace.
NodeList childNodes = node.getChildNodes();
for (int i = 0, l = childNodes.getLength(); i < l; i++) {
    Node child = childNodes.item(i);
    if (isInstance(child, namespace, name)) {
        return child;
return null;
...
NodegetFirstChild(Node node, String xmlLocalName)
Returns the first child element with the given XML local name.
String nsUri = node.getNamespaceURI();
for (Node child = node.getFirstChild(); child != null; child = child
        .getNextSibling()) {
    if (child.getNodeType() == Node.ELEMENT_NODE
            && nsUri.equals(child.getNamespaceURI())) {
        if (xmlLocalName == null
                || xmlLocalName.equals(child.getLocalName())) {
            return child;
...
NodegetFirstMatchingChildNode(Node node, String nodeName)
get First Matching Child Node
return getFirstMatchingChildNode(node, nodeName, null, null);
NodegetFirstMatchingChildNode(Node node, String nodeName, String attributeName, List attributeValues)
get First Matching Child Node
if (node == null || nodeName == null) {
    return null;
List<Node> nodes = getMatchingChildNodes(node, nodeName,
        attributeName, attributeValues);
return (nodes == null || nodes.isEmpty()) ? null : (Node) nodes
        .get(0);