Java XML Node Text Value getDescendentText(Node node, String name)

Here you can find the source of getDescendentText(Node node, String name)

Description

get Descendent Text

License

Open Source License

Declaration

public static String getDescendentText(Node node, String name) throws IOException 

Method Source Code


//package com.java2s;
/*/*from   w  w  w  .j  a  va  2 s.c  om*/
 * XmlUtil.java
 *
 * (c) 2009  The Echo Nest
 * See "license.txt" for terms
 *
 *
 */

import java.io.IOException;

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

public class Main {
    public static String getDescendentText(Node node, String name) throws IOException {
        Node d = getDescendent(node, name);
        if (d != null) {
            return d.getTextContent().trim();
        }
        return null;
    }

    public static Node getDescendent(Node node, String nodeName) throws IOException {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeName().equals(nodeName)) {
                return child;
            }
        }
        return null;
    }
}

Related

  1. findNodeText(Node node)
  2. get_inner_text(Node node)
  3. getAppInfoText(final Node node)
  4. getContentsOfTextOnlyNode(Node n)
  5. getContentText(Node n)
  6. getDirectText(org.w3c.dom.Element node)
  7. getElementText(Node elem)
  8. getFirstExtensionNode(Node extensionsNode)
  9. getFirstExtensionNodeFromWorkingSet(Node extensionsNode, String workingSetName)