Java XML Node Text Value getTextContents(Node node)

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

Description

(A useful utility method from IBM developerworks)

License

Open Source License

Declaration

public static String getTextContents(Node node) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004-2010 IBM Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from   w  w  w .j av a 2 s  .c o  m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

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

public class Main {
    /**
     * (A useful utility method from IBM developerworks)
     */
    public static String getTextContents(Node node) {
        NodeList childNodes;
        StringBuffer contents = new StringBuffer();

        childNodes = node.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) {
                contents.append(childNodes.item(i).getNodeValue());
            }
        }
        return contents.toString();
    }
}

Related

  1. getTextContent(Node node)
  2. getTextContent(Node node, String defaultValue)
  3. getTextContent(Node node, String path)
  4. getTextContent(org.w3c.dom.Node element)
  5. getTextContentOld(final Node node)
  6. getTextData(Node element)
  7. getTextData(Node node)
  8. getTextForNode(Node node)
  9. getTextForNode(Node node)