Android examples for XML:XML Child Element
Returns the direct child node of the specified XML element having specified name.
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/* w w w . ja va 2 s . co m*/ * Returns the direct child node of the specified element having specified name. */ public static Element directChild(Element parent, String childName) { final NodeList nodeList = parent.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); if (node instanceof Element) { final Element element = (Element) node; if (element.getTagName().equals(childName)) { return element; } } } return null; } }