Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { /** * Given a todo element, we must get the element specified * by the tagName, then must traverse that Node to get the * value. * @param e * @param tagName * @return the value of the corresponding element */ public static String getValue(Element e, String tagName) { try { // Get node lists of a tag name from an Element NodeList elements = e.getElementsByTagName(tagName); Node node = elements.item(0); NodeList nodes = node.getChildNodes(); // Find a value whose value is non-whitespace String s; for (int i = 0; i < nodes.getLength(); i++) { s = ((Node) nodes.item(i)).getNodeValue().trim(); if (s.equals("") || s.equals("\r")) { continue; } else { return s; } } } catch (Exception ex) { return null; } return null; } }