Java XML Node Text Value getText(Node node)

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

Description

get Text

License

Open Source License

Declaration

public static String getText(Node node) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

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

public class Main {
    public static String getText(Node node) {
        StringBuffer result = new StringBuffer();
        NodeList nodes = node.getChildNodes();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node2 = nodes.item(i);
            if (node2.getNodeType() == Node.TEXT_NODE || node2.getNodeType() == Node.CDATA_SECTION_NODE) {
                String value = node2.getNodeValue();
                result.append(value);//from w w w.  j  a va2 s . c o m
            }
        }
        return result.toString().trim();
    }
}

Related

  1. getText(Node n)
  2. getText(Node nd)
  3. getText(Node nd, StringBuilder buf)
  4. getText(Node node)
  5. getText(Node node)
  6. getText(Node node)
  7. getText(Node node)
  8. getText(Node node)
  9. getText(Node node)