Java XML Child Get getChild(Node node, String name)

Here you can find the source of getChild(Node node, String name)

Description

get Child

License

Apache License

Declaration

public static Node getChild(Node node, String name) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static Node getChild(Node node, String name) {
        if (!node.hasChildNodes())
            return null;
        NodeList lst = node.getChildNodes();
        if (lst == null)
            return null;
        for (int i = 0; i < lst.getLength(); i++) {
            Node child = lst.item(i);
            if (name.equals(child.getNodeName()))
                return child;
        }/*from  ww w  . j  a v a  2s  .c o  m*/
        return null;
    }

    public static Node getChild(Node node, String name, String errMsg) {
        Node result = getChild(node, name);
        if (result == null) {
            throw new RuntimeException(errMsg + ": missing mandatory attribute node '" + name + "'");
        }
        return result;
    }
}

Related

  1. getChild(final Element element, final String tagName)
  2. getChild(final Element parent, final String tag)
  3. getChild(final Element root, final String name)
  4. getChild(final Element root, final String name)
  5. getChild(Node n, String name)
  6. getChild(Node node, String name)
  7. getChild(Node node, String name, String attrName, String attrValue)
  8. getChild(Node parent, String name)
  9. getChild(Node parent, String name)