Java XML Element Get getElementArray(Element config, String elementName)

Here you can find the source of getElementArray(Element config, String elementName)

Description

get Element Array

License

Open Source License

Declaration

public static Element[] getElementArray(Element config, String elementName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

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

public class Main {
    public static Element[] getElementArray(Element config, String elementName) {
        NodeList children = config.getChildNodes();
        Node node;//from ww w  .ja v a  2s. co m
        ArrayList arrayList = new ArrayList();
        for (int counter = 0; counter < children.getLength(); counter++) {
            node = children.item(counter);
            if (node instanceof Element) {
                if (((Element) node).getTagName().equals(elementName)) {
                    arrayList.add(node);
                }
            }
        }
        Element[] elementArray = new Element[arrayList.size()];
        elementArray = (Element[]) arrayList.toArray(elementArray);
        return elementArray;
    }
}

Related

  1. getElement(Element element, String tagName)
  2. getElement(Element element, String tagName, String namespace)
  3. getElement(Element root, String name)
  4. getElement(final Document doc, final String expression)
  5. getElement(SOAPMessage message, String tagname, String nsURI, int whichOne)
  6. getElementAsBoolean(Element e, String name)
  7. getElementAsFloat(Element e, String name, Float dft)
  8. getElementAsInt(Element element)
  9. getElementAttributeValue(Document doc, String tagName, String attributeName)