Java XML Has Child hasChildElement(Element elem, String namespace, String localName)

Here you can find the source of hasChildElement(Element elem, String namespace, String localName)

Description

Checks if a DOM Element has a child element with the given qualified name.

License

Apache License

Parameter

Parameter Description
elem A DOM Element.
namespace A namespace name (absolute URI).
localName A String representing the local name of an element.

Return

true if one or more matching child elements are present; false otherwise.

Declaration

public static boolean hasChildElement(Element elem, String namespace, String localName) 

Method Source Code

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

import org.w3c.dom.Element;

public class Main {
    /**// w  w  w  .j  a v  a  2s  . co m
     * Checks if a DOM Element has a child element with the given qualified
     * name.
     * 
     * @param elem
     *            A DOM Element.
     * @param namespace
     *            A namespace name (absolute URI).
     * @param localName
     *            A String representing the local name of an element.
     * 
     * @return {@code true} if one or more matching child elements are present;
     *         {@code false} otherwise.
     */
    public static boolean hasChildElement(Element elem, String namespace, String localName) {
        return elem.getElementsByTagNameNS(namespace, localName).getLength() > 0;
    }
}

Related

  1. hasChild(Element node, String name)
  2. hasChild(Element parent, String nodeName)
  3. hasChild(Element root, String childName)
  4. hasChild(Element start, String name)
  5. hasChild(Node n)
  6. hasChildElement(Element element, String name)
  7. hasChildElement(NodeList list)
  8. hasChildElement(TreeWalker walker)
  9. hasChildElementNodes(@Nonnull final Node aStartNode)