Java XML Child Get getChildElements(Element el)

Here you can find the source of getChildElements(Element el)

Description

Gets a list of the given element's child DOM elements.

License

Open Source License

Declaration

public static Vector getChildElements(Element el) 

Method Source Code


//package com.java2s;

import java.util.Vector;

import org.w3c.dom.*;

public class Main {
    /** Gets a list of the given element's child DOM elements. */
    public static Vector getChildElements(Element el) {
        return getChildElements(null, el);
    }//  w w w .  j a  v a2 s  . com

    /**
     * Gets a list of the given element's child DOM elements
     * with the specified name, or all child elements if name is null.
     */
    public static Vector getChildElements(String name, Element el) {
        if (el == null)
            return null;
        Vector v = new Vector();
        NodeList list = el.getChildNodes();
        int size = list.getLength();
        String cName = ":" + name;
        for (int i = 0; i < size; i++) {
            Node node = list.item(i);
            if (!(node instanceof Element))
                continue;
            String nodeName = node.getNodeName();
            //if (name == null || name.equals(getName(node))) v.add(node);
            if (name == null || nodeName.equals(name) || nodeName.endsWith(cName)) {
                v.add(node);
            }
        }
        return v;
    }
}

Related

  1. getChild(Node parent, String name)
  2. getChild(Node parent, String name)
  3. getChildElements(Element e)
  4. getChildElements(Element e)
  5. getChildElements(Element e, String tag)
  6. getChildElements(Element ele)
  7. getChildElements(Element ele)
  8. getChildElements(Element ele)
  9. getChildElements(Element ele, String childEleName)