Java XML Element Get by Name getElement(Node parent, int index)

Here you can find the source of getElement(Node parent, int index)

Description

get Element

License

Apache License

Declaration

public static Element getElement(Node parent, int index) 

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 getElement(Node parent, int index) {
        int j = 0;
        NodeList nodes = parent.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            if (node instanceof Element) {
                if (j == index) {
                    return (Element) node;
                }/*from w ww. ja  v a 2  s.c o  m*/
                j++;
            }
        }
        return null;
    }
}

Related

  1. getElement(Element parent, String elementName)
  2. getElement(Element parent, String localname, int position)
  3. getElement(Element parent, String tagName)
  4. getElement(Element parent, String tagName)
  5. getElement(Element parentElement, String nodeName)
  6. getElement(String elementName, Element parentElement)
  7. getElement(String name, int index, Element parent)
  8. getElementByName(Document document, String name)
  9. getElementByName(Element eParent, String elementName)