Java XML Node Text Value getNormalizedText(Node node)

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

Description

get Normalized Text

License

Open Source License

Declaration

public static String getNormalizedText(Node node) 

Method Source Code

//package com.java2s;
/*/*from w ww. jav a  2  s.c o  m*/
 * Copyright (c) 2001-2011 Convertigo SA.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero 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/>.
 *
 * $URL$
 * $Author$
 * $Revision$
 * $Date$
 */

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    public static String getNormalizedText(Node node) {
        String res = "";
        if (node.hasChildNodes()) {
            NodeList nl = node.getChildNodes();
            for (int i = 0; i < nl.getLength(); i++) {
                if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
                    res += nl.item(i).getNodeValue();
                } else {
                    // ignore <SCRIPT> nodes ...
                    if (!nl.item(i).getNodeName().equalsIgnoreCase("script"))
                        res += getNormalizedText(nl.item(i));
                }
            }
        }
        return res;
    }
}

Related

  1. getNodeTextValue(Node node)
  2. getNodeTextValue(Node node)
  3. getNodeTextValue(Node node)
  4. getNodeTextValue(Node node)
  5. getNodeTextValue(Node pElement)
  6. getPlainTextBelow(Node n)
  7. getPropertiesFromXML(Node propNode)
  8. getPropertiesFromXML(Node propNode)
  9. getPropText(Node node)