Java tutorial
//package com.java2s; // Released under the terms of the CPL Common Public License version 1.0. import org.w3c.dom.*; public class Main { public static String getLocalTextValue(Element element, String name) { Element namedElement = getLocalElementByTagName(element, name); return getElementText(namedElement); } public static Element getLocalElementByTagName(Element context, String tagName) { NodeList childNodes = context.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element && tagName.equals(node.getNodeName())) return (Element) node; } return null; } public static String getElementText(Element namedElement) { if (namedElement == null) { return null; } String text = namedElement.getTextContent(); return (text.isEmpty()) ? null : text; } }