Java XML First Child Element getDirectChildNamedElements( Element parent, String name)

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

Description

Returns a collection of direct child Elements that match the specified tag name

License

Open Source License

Parameter

Parameter Description
parent the parent whose direct children will be processed
name the child tag name to match

Return

a collection of matching Elements

Declaration

public static ArrayList<Element> getDirectChildNamedElements(
        Element parent, String name) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;

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

public class Main {
    /**/*from w ww  .  ja  v a  2 s.  co  m*/
     * Returns a collection of direct child Elements that match the specified tag name
     * @param parent the parent whose direct children will be processed
     * @param name the child tag name to match
     * @return a collection of matching Elements
     */
    public static ArrayList<Element> getDirectChildNamedElements(
            Element parent, String name) {
        ArrayList<Element> result = new ArrayList<Element>();

        for (Node child = parent.getFirstChild(); child != null; child = child
                .getNextSibling()) {
            if (child instanceof Element
                    && name.equals(child.getNodeName())) {
                result.add((Element) child);
            }
        }

        return result;
    }
}

Related

  1. getDirectChildElements(Element parent)
  2. getDirectChildElements(Node fNode, String localName, String namespace)
  3. getDirectChildElementsByTag(Element node, String tag)
  4. getDirectChildElementValue(Element p_rootElement, String p_elementName)
  5. getDirectChildElementValues(Element p_rootElement, String p_elementName)
  6. getDirectChildNode(Node node, String name)
  7. getDirectChildNodes(final Node parent, final String... nodeNames)
  8. getDirectChildNodes(Node node, String name)
  9. getFirstChild(Element e)