Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getChildText(Element parent, String name) { Element child = getChild(parent, name); if (child != null) { return getText(child); } return null; } public static Element getChild(Element parent, String name) { NodeList children = parent.getChildNodes(); final int length = children.getLength(); for (int index = 0; index < length; index++) { Node node = children.item(index); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } Element element = (Element) node; if (name.equalsIgnoreCase(element.getNodeName())) { return element; } } return null; } public static String getText(Element node) { NodeList children = node.getChildNodes(); if (0 < children.getLength()) { String value = children.item(0).getNodeValue(); if (value != null) { return value.trim(); } } return null; } }