Java XML Has Child hasNamedChild(Element e, String name)

Here you can find the source of hasNamedChild(Element e, String name)

Description

has Named Child

License

Open Source License

Declaration

public static boolean hasNamedChild(Element e, String name) 

Method Source Code

//package com.java2s;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static boolean hasNamedChild(Element e, String name) {
        Element c = getFirstChild(e);
        while (c != null && !name.equals(c.getLocalName())
                && !name.equals(c.getNodeName()))
            c = getNextSibling(c);//  w ww . j av  a  2 s  .c o m
        return c != null;
    }

    public static Element getFirstChild(Element e) {
        if (e == null)
            return null;
        Node n = e.getFirstChild();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
            n = n.getNextSibling();
        return (Element) n;
    }

    public static Element getNextSibling(Element e) {
        Node n = e.getNextSibling();
        while (n != null && n.getNodeType() != Node.ELEMENT_NODE)
            n = n.getNextSibling();
        return (Element) n;
    }
}

Related

  1. hasElementChild(Node node)
  2. hasElementChild(Node node)
  3. hasElementChildren(Element element)
  4. hasElementChildren(Element elemNode)
  5. hasElementChildren(Element elemNode)
  6. hasNonWhitespaceChildren(Element element)
  7. hasOnlyTextChildNodes(final Node node)
  8. hasOnlyTextChildren( Node node)
  9. hasTextChildNodesOnly(Node node)