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.Text; public class Main { /** * @param el * @return the first text child of an element, or null if it has none */ public static Text firstTextChild(Element el) { Text text = null; for (int i = 0; i < el.getChildNodes().getLength(); i++) { Node n = el.getChildNodes().item(i); if (n instanceof Text) text = (Text) n; } return text; } }