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

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

Description

value Of First Descendant With Name

License

Open Source License

Declaration

public static String valueOfFirstDescendantWithName(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 w ww.  j ava 2s . co  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 String valueOfFirstDescendantWithName(Element element,
            String name) {
        Element e = firstDescendantWithName(element, name);
        if (e != null) {
            return e.getFirstChild().getNodeValue();
        }

        return null;
    }

    public static Element firstDescendantWithName(Element element,
            String name) {
        NodeList list = element.getElementsByTagName(name);
        if (list.getLength() > 0) {
            Node n = list.item(0);
            if (n.getNodeType() == Node.ELEMENT_NODE)
                return (Element) n;
        }

        return null;
    }
}

Related

  1. attributeOfFirstChildWithName(Element element, String name, String attribute)
  2. childrenWithName(Element e, String name)
  3. getCDataNode(Element element)
  4. locateElements(Element root, String tagName, String keyAttributeName, String keyAttributeValue)
  5. locateElement(Element root, String tagName, String keyAttributeName, String keyAttributeValue)
  6. firstDescendantWithName(Element element, String name)
  7. findNextSiblingElement(Element current)
  8. GetElement(Element root, String namespaceUri, String name, boolean throwIfNotFound)
  9. getListContent(Element listElement, String listItemName, String listItemNamespace)