Java XML Child Get getChild(Element parent, int i)

Here you can find the source of getChild(Element parent, int i)

Description

get Child

License

Apache License

Declaration

public static Element getChild(Element parent, int i) 

Method Source Code

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

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

public class Main {
    public static Element getChild(Element parent, int i) {
        NodeList children = parent.getChildNodes();
        if (children.getLength() == 0)
            return null;
        int count = 0;
        for (int k = 0; k < children.getLength(); k++) {
            Node kid = children.item(k);
            if (kid instanceof Element) {
                if (count == i)
                    return (Element) kid;
                else
                    ++count;//  www.java2 s . c  o  m
            }
        }
        return null;
    }
}

Related

  1. getChild(Element element, String child)
  2. getChild(Element element, String name)
  3. getChild(Element element, String name)
  4. getChild(Element element, String name)
  5. getChild(Element node, String tagName)
  6. getChild(Element parent, String element)
  7. getChild(Element parent, String name)
  8. getChild(Element parent, String name)
  9. getChild(Element parent, String name)