Java tutorial
//package com.java2s; //License from project: Open Source License import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; public class Main { public static String getNodeString(Element elem, String name, int inx) { NodeList nl = elem.getElementsByTagName(name); if (inx >= nl.getLength()) return null; Element element = (Element) nl.item(inx); return getSimpleElementText(element); } public static String getSimpleElementText(Element node) { if (node == null) return null; StringBuffer sb = new StringBuffer(); NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Text) { sb.append(child.getNodeValue()); } } return sb.toString(); } }