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

private static String getText(Node node) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 Firestar Software, Inc.
 * 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   ww  w .j a v a2 s .c  o m*/
 *     Firestar Software, Inc. - initial API and implementation
 *
 * Author:
 *     Gabriel Oancea
 *
 *******************************************************************************/

import org.w3c.dom.*;

public class Main {
    private static String getText(Node node) {
        if (node == null)
            return null;
        NodeList lst = node.getChildNodes();
        int size = lst.getLength();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < size; i++) {
            Node n = lst.item(i);
            if (n.getNodeType() == Node.TEXT_NODE) {
                Text t = (Text) n;
                sb.append(t.getData());
            }
        }
        return sb.toString();
    }
}

Related

  1. getText(Node node)
  2. getText(Node node)
  3. getText(Node node)
  4. getText(Node node)
  5. getText(Node node)
  6. getText(Node node)
  7. getText(Node node)
  8. getText(Node node)
  9. getText(Node node)