Java XML Node Text Value getTexto(Node n)

Here you can find the source of getTexto(Node n)

Description

Devuelve el texto de un nodo: TEXTO

License

Open Source License

Parameter

Parameter Description
n a parameter

Declaration

public static String getTexto(Node n) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/*from w w  w  .  ja va  2 s  . c  om*/
     * Devuelve el texto de un nodo: <tag>TEXTO</tag>
     *
     * @param n
     * @return
     */
    public static String getTexto(Node n) {
        NodeList nl = n.getChildNodes();
        Node act = null;

        for (int i = 0; i < nl.getLength(); i++) {
            act = nl.item(i);
            if (act == null)
                return null;
            if ((act.getNodeType() == Node.CDATA_SECTION_NODE) || (act.getNodeType() == Node.TEXT_NODE))
                return act.getNodeValue();
        }
        return "";
    }
}

Related

  1. getTextData(Node node)
  2. getTextForNode(Node node)
  3. getTextForNode(Node node)
  4. getTextForNode(Node node)
  5. getTextFromNode(Node node, String defaultValue)
  6. getTextOfEl(Node e)
  7. getTextTrim(Node node)
  8. getTextValue(Node node)
  9. getTextValue(Node node)