Java XML Child Get by Name getChildElements(Element parent, String name)

Here you can find the source of getChildElements(Element parent, String name)

Description

get Child Elements

License

Open Source License

Declaration

public static Element[] getChildElements(Element parent, String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Chase Technology Ltd - http://www.chasetechnology.co.uk
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  ww  . j a  va2 s .  c  o m*/
 *     Doug Satchwell (Chase Technology Ltd) - initial API and implementation
 *******************************************************************************/

import java.util.ArrayList;
import java.util.List;

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

public class Main {
    public static Element[] getChildElements(Element parent, String name) {
        List<Element> children = new ArrayList<Element>();
        NodeList list = parent.getChildNodes();
        int length = list.getLength();
        for (int i = 0; i < length; ++i) {
            Node node = list.item(i);
            short type = node.getNodeType();
            if (type == Node.ELEMENT_NODE) {
                Element processorElement = (Element) node;
                if (processorElement.getNodeName().equals(name)) {
                    children.add(processorElement);
                }
            }
        }
        return children.toArray(new Element[0]);
    }
}

Related

  1. getChildElements(Element p_rootElement, String p_elementName)
  2. getChildElements(Element parent, String elementTag)
  3. getChildElements(Element parent, String localName)
  4. getChildElements(Element parent, String name)
  5. getChildElements(Element parent, String name)
  6. getChildElements(Element parent, String nsUri, String localPart)
  7. getChildElements(Element parent, String nsUri, String localPart)
  8. getChildElements(Element parent, String tagName)
  9. getChildElements(Element parent, String tagName)