Java XML First Child Element readFirstChild(Node parentNode, String nodeName)

Here you can find the source of readFirstChild(Node parentNode, String nodeName)

Description

read First Child

License

Apache License

Declaration

public static Element readFirstChild(Node parentNode, String nodeName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import org.w3c.dom.Element;

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

public class Main {

    public static Element readFirstChild(Node parentNode, String nodeName) {
        if (parentNode != null) {
            NodeList children = parentNode.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                if (children.item(i).getNodeName().equals(nodeName))
                    return (Element) children.item(i);
            }//from   w ww .  ja  v  a 2  s  .c o  m
        }
        return null;
    }
}

Related

  1. getFirstTextChild(Node n)
  2. getFirstTextChild(Node node)
  3. getFirstVisibleChildElement(Node parent)
  4. getValueOfFirstElementChild(final Element element, final String namespace, final String localname)
  5. insertBeforeFirstChild(Element object, Element attrId)
  6. VectoriseFirstChildrenNodes(Node node, Vector elements)
  7. xmlFirstChild(final Element parent, final String childName, final boolean isThrow)