Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { /**gets string associated with a node * @param node node to get string for * @param string associated with the input node*/ static public String getAssociatedString(Node node) { // Has to be a real Node if (node == null) return null; // Must have one and only one string associted with it NodeList children = node.getChildNodes(); if (children.getLength() > 1) { System.out.println("XMLUtils: Node has more than one child"); return null; } Node firstChild = children.item(0); if (firstChild.getNodeType() != Node.TEXT_NODE) { System.out.println("XMLUtils: Node is not a text node"); System.out.println( "XMLUtils: Node = " + firstChild.getNodeName() + ", Parent Node = " + node.getNodeName()); return null; } String stringToReturn = firstChild.getNodeValue().trim(); if (stringToReturn.equals("")) { System.out.println("XMLUtils: Trimmed string is empty"); return null; } else return stringToReturn; } }