Java XML Node Text Value getNodeText(Node node)

Here you can find the source of getNodeText(Node node)

Description

get Node Text

License

Open Source License

Declaration

public static String getNodeText(Node node) 

Method Source Code

//package com.java2s;
/**/*  www.j a v a 2  s .  c  om*/
 * 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 "";
    }
}

Related

  1. getNamespaceURIFromPrefix(Node context, String prefix)
  2. getNodeText(final Node node)
  3. getNodeText(Node node)
  4. getNodeText(Node node)
  5. getNodeText(Node node)
  6. getNodeText(Node node)
  7. getNodeText(Node node)
  8. getNodeText(Node t)
  9. getNodeText(org.w3c.dom.Node node)