Android XML Element Child Get childrenWithName(Element e, String name)

Here you can find the source of childrenWithName(Element e, String name)

Description

children With Name

License

Open Source License

Declaration

public static List<Element> childrenWithName(Element e, String name) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Jose Alcal? Correa.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * /*from   www. java 2 s.  c  o m*/
 * Contributors:
 *     Jose Alcal? Correa - 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 List<Element> childrenWithName(Element e, String name) {
        final List<Element> ret = new ArrayList<Element>();

        NodeList list = e.getChildNodes();
        final int length = list.getLength();
        for (int i = 0; i < length; ++i) {
            Node n = list.item(i);
            if (n.getNodeType() == Node.ELEMENT_NODE
                    && n.getNodeName().equals(name))
                ret.add((Element) n);
        }

        return ret;
    }
}

Related

  1. getChildValue(Element element, String name)
  2. getFullTextChildrenFromElement(Element element)
  3. printChildElements(Element root, PrintStream out, boolean recurse, String prefix)
  4. valueOfFirstChildWithName(Element element, String name)
  5. attributeOfFirstChildWithName(Element element, String name, String attribute)
  6. getCDataNode(Element element)
  7. locateElements(Element root, String tagName, String keyAttributeName, String keyAttributeValue)
  8. locateElement(Element root, String tagName, String keyAttributeName, String keyAttributeValue)
  9. valueOfFirstDescendantWithName(Element element, String name)