Java XML First Child Element getFirstChildByType(Element element, int nodeType)

Here you can find the source of getFirstChildByType(Element element, int nodeType)

Description

get First Child By Type

License

Open Source License

Declaration

public static Node getFirstChildByType(Element element, int nodeType) 

Method Source Code

//package com.java2s;
// License as published by the Free Software Foundation; either

import org.w3c.dom.Element;

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

public class Main {
    public static Node getFirstChildByType(Element element, int nodeType) {
        NodeList children = element.getChildNodes();
        int childCount = children.getLength();

        for (int i = 0; i < childCount; i++) {
            Node child = children.item(i);
            if (child.getNodeType() == nodeType) {
                return child;
            }//ww  w  .  ja v a 2  s  . c  o  m
        }

        return null;
    }
}

Related

  1. getFirstChildByNS(Element node, String ns, String localName)
  2. getFirstChildByRegex(Element ele, String pattern)
  3. getFirstChildByTagName(Element parent, String tagName)
  4. getFirstChildByTagName(Node parent, String tagName)
  5. getFirstChildByTagNameNS(Node contextNode, String nsuri, String tag)
  6. getFirstChildByType(Element element, short nodeType)
  7. getFirstChildElement(@Nonnull final Node aStartNode)
  8. getFirstChildElement(Element e)
  9. getFirstChildElement(Element e)