Java examples for XML:DOM Node Value
get XML Node Strings By Name
//package com.java2s; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**/*from w w w . j ava 2 s .c o m*/ * * @param n * @param name * @param sbStrings * this function aims at grabbing all title strings under current sourceOfNode. * @return */ public static String getNodeStringsByName(Node n, String name, StringBuffer sbStrings) { NodeList l = n.getChildNodes(); if (l == null) return sbStrings.toString(); for (int i = 0; i < l.getLength(); i++) { if (l.item(i).getNodeName().equals(name)) { sbStrings.append(l.item(i).getTextContent() + " "); } else { getNodeStringsByName(l.item(i), name, sbStrings); } } return sbStrings.toString(); } }