Java XML Child Node Get getChildNodeTextContent(Node parentNode, String childElementName)

Here you can find the source of getChildNodeTextContent(Node parentNode, String childElementName)

Description

get Child Node Text Content

License

Apache License

Declaration

public static String getChildNodeTextContent(Node parentNode,
            String childElementName) 

Method Source Code

//package com.java2s;
// Licensed to the Apache Software Foundation (ASF) under one

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

public class Main {
    public static String getChildNodeTextContent(Node parentNode,
            String childElementName) {
        Node node = getChildNode(parentNode, childElementName);
        if (node != null)
            return node.getTextContent();
        return null;
    }/*from   w  ww.java  2  s.  com*/

    public static Node getChildNode(Node parentNode, String childElementName) {
        NodeList l = parentNode.getChildNodes();
        for (int i = 0; i < l.getLength(); i++) {
            Node node = l.item(i);
            if (node.getNodeName().equals(childElementName))
                return node;
        }
        return null;
    }
}

Related

  1. getChildNodesByName(Node node, String name)
  2. getChildNodesByTagName(final Element element, final String tagName)
  3. getChildNodesWithName(Node node, String name)
  4. getChildNodeText(Element element, String nodeTagName)
  5. getChildNodeText(Node root, String childName)
  6. getChildNodeTextContents(Node node, String name)
  7. getChildNodeValue(Element node, String tagName)
  8. getChildNodeValue(Element root, String childNodeName, String defaultValue)
  9. getChildNodeValue(Node node, String elementName)