Java XML First Child Element getFirstChildElement(Node node)

Here you can find the source of getFirstChildElement(Node node)

Description

get First Child Element

License

Open Source License

Declaration

public static Element getFirstChildElement(Node node) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Node;

import org.w3c.dom.Element;

public class Main {
    public static Element getFirstChildElement(Node node) {
        return getNthChildElement(node, 0);
    }//from  w ww.j a  v a2s.c  om

    public static Element getNthChildElement(Node node, int index) {
        int i = 0;

        Node child = node.getFirstChild();
        while (child != null) {
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                if (index == i) {
                    return (Element) child;
                }
                ++i;
            }

            child = child.getNextSibling();
        }

        return null;
    }
}

Related

  1. getFirstChildElement(Node node)
  2. getFirstChildElement(Node node)
  3. getFirstChildElement(Node node)
  4. getFirstChildElement(Node node)
  5. getFirstChildElement(Node node)
  6. getFirstChildElement(Node node, String tag)
  7. getFirstChildElement(Node parent)
  8. getFirstChildElement(Node parent)
  9. getFirstChildElement(Node parent)