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

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

Description

get Child

License

Open Source License

Declaration

public static Node getChild(Node n, String name) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static Node getChild(Node n, String name) {
        return getChildWithIndex(n, name, 0);
    }//w w w .  java  2s .  c  o m

    public static Node getChildWithIndex(Node n, String name, int index) {
        NodeList c = n.getChildNodes();
        for (int i = 0; i < c.getLength(); i++) {
            if (c.item(i).getNodeName().equalsIgnoreCase(name)) {
                if (index <= 0)
                    return c.item(i);
                else
                    --index;
            }
        }
        return null;
    }
}

Related

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