Source Code : Get the first text node associated with this element
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Get the first text node associated with this element
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
public class Utils {
public static String getFirstText(Node parent) {
return getTextNodeByNumber(parent, 1);
}
public static String getTextNodeByNumber(Node parent, int number) {
String text = null;
int count = 1;
if (parent != null) {
for (Node child = parent.getFirstChild();
child != null;
child = child.getNextSibling()) {
if ((child.getNodeType() == Node.TEXT_NODE) && (count++ == number)) {
text = child.getNodeValue();
return text.trim();
}
}
}
return text;
}
}
Thank with us