Java tutorial
//package com.java2s; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.Text; public class Main { public static synchronized String getElementValue(Element element) { if (element == null) { return null; } String retnStr = null; for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Text) { String str = node.getNodeValue(); if (str == null || str.length() == 0 || str.trim().length() == 0) { continue; } else { retnStr = str; break; } } } return retnStr; } }