Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { /** * Get the content of the given element. * @param element The element to get the content for. * @param defaultStr The default to return when there is no content. * @return The content of the element or the default. */ public static String getElementContent(Element element, String defaultStr) { if (element == null) return defaultStr; NodeList children = element.getChildNodes(); String result = ""; for (int i = 0; i < children.getLength(); i++) { if (children.item(i).getNodeType() == Node.TEXT_NODE || children.item(i).getNodeType() == Node.CDATA_SECTION_NODE) { result += children.item(i).getNodeValue(); } } return result.trim(); } }