Java XML Element First getFirstElement(Element documentElement)

Here you can find the source of getFirstElement(Element documentElement)

Description

get First Element

License

LGPL

Declaration

public static Element getFirstElement(Element documentElement) 

Method Source Code

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

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static Element getFirstElement(Element documentElement) {
        Object node = null;//from  w w  w  . jav a 2  s .c o m
        NodeList childs = documentElement.getChildNodes();
        for (int i = 0; i < childs.getLength(); i++) {
            node = childs.item(i);
            if (node instanceof Element)
                return (Element) node;
        }
        throw new RuntimeException("Can't find any Element");
    }
}

Related

  1. getFirstElement(Document document)
  2. getFirstElement(Document document, String tagName)
  3. getFirstElement(String name, Element root)
  4. getFirstElementByTagName(Document doc, String tagName)
  5. getFirstElementByTagName(Document document, String name)
  6. getFirstElementByTagName(Document document, String tag)