Here you can find the source of getNodeContent(Node n, String nodename)
public static String getNodeContent(Node n, String nodename)
//package com.java2s; /******************************************************************************* * * JOpac2 (C) 2002-2007 JOpac2 project//from w w w. j a v a2 s .co m * * This file is part of JOpac2. http://jopac2.sourceforge.net * * JOpac2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * JOpac2 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JOpac2; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *******************************************************************************/ import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String getNodeContent(Node n, String nodename) { Node r = getNode(n, nodename); if (r != null) return r.getTextContent(); else return null; } public static Node getNode(Node node, String nodename) { Node r = null; if (node.getNodeName().equals(nodename)) { r = node; } else { NodeList children = node.getChildNodes(); int len = children.getLength(); for (int i = 0; i < len && r == null; i++) r = getNode(children.item(i), nodename); } return r; } }