Java tutorial
//package com.java2s; /** * XmlHelper - A class that encapsulates some helpful XML DOM tree functions for * the NwsClient Blackberry weather application. * * Copyright (c) 2009 Doug Letterman * * This program 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 3 of the License, or * (at your option) any later version. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */ import org.w3c.dom.*; public class Main { public static String getNodeText(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList childNodes = node.getChildNodes(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) { Node myNode = childNodes.item(i); buffer.append(myNode.getNodeValue()); } } return buffer.toString(); } return ""; } }