Android XML Element Child Get firstChildWithName(Element element, String name)

Here you can find the source of firstChildWithName(Element element, String name)

Description

first Child With Name

License

Open Source License

Declaration

public static Element firstChildWithName(Element element, 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   ww w  .  j  a v  a 2 s  .c  o m
 * Contributors:
 *     Jose Alcal? Correa - initial API and implementation
 ******************************************************************************/

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

public class Main {
    public static Element firstChildWithName(Element element, String name) {
        NodeList list = element.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))
                return (Element) n;
        }

        return null;
    }
}

Related

  1. findChild(Element parent, String tagName)
  2. findChildElement(Element parent, String name)
  3. findChildElementWithAttribute(Element parent, String name, String attribute, String value)
  4. findChildren(Element parent, String tagName)
  5. findFirstChildElement(Element parent)
  6. getChild(Element element, String name)
  7. getChildByType(Element element, short nodeType)
  8. getChildElementByName(Element parent, String name)
  9. getChildValue(Element element, String name)