Java Utililty Methods XML Has Child

List of utility methods to do XML Has Child

Description

The list of methods to do XML Has Child are organized into topic(s).

Method

booleanhasChildElements(Node node)
Test whether the input element has a child element.
boolean result = false;
if (node != null) {
    NodeList children = node.getChildNodes();
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                result = true;
...
booleanhasChildElements(Node node)
Checks if a Node has a valid element
NodeList nodelist = node.getChildNodes();
for (int i = 0; i < nodelist.getLength(); i++) {
    Node childNode = nodelist.item(i);
    if (childNode.getNodeType() == Node.ELEMENT_NODE) {
        return true;
return false;
...
booleanhasChildElementWithAttribute(Element element, String attributeName, String attributeValue)
Looks for a childelement with an attribute with the given name and value
if (element == null) {
    return false;
for (int i = 0; i < element.getChildNodes().getLength(); i++) {
    Node child = element.getChildNodes().item(i);
    if ((child.getAttributes().getNamedItem(attributeName) != null)
            && child.getAttributes().getNamedItem(attributeName).getNodeValue().equals(attributeValue)) {
        return true;
...
booleanhasChildNode(Element root, String childNodeName)
has Child Node
NodeList nl = root.getElementsByTagName(childNodeName);
return (nl.getLength() > 0);
booleanhasChildNode(Node parentNode, String nodeName)
Determine if the parent node contains a child node with matching name
return getChildNode(parentNode, nodeName, null) != null ? true : false;
booleanhasChildNodeByName(Node element, CharSequence nodeName, boolean caseSensitive)
Indicates if the passed node has a child node of the passed name
if (element == null)
    return false;
if (nodeName == null)
    return false;
final String name = nodeName.toString().trim();
if (name.isEmpty())
    return false;
NodeList list = element.getChildNodes();
...
booleanhasChildNodes(Element element, String name)
Check if the given Element contains child nodes that match with the given child name.
NodeList elements = element.getElementsByTagName(name);
return elements.getLength() > 0;
booleanhasChildNS(Node parent, String ns, String name)
has Child NS
if (parent == null)
    return false;
for (Node c = parent.getFirstChild(); c != null; c = c.getNextSibling()) {
    if (isA(c, ns, name))
        return true;
return false;
booleanhasChildOfType(final Element e, final String name)
has Child Of Type
for (Node child = e.getFirstChild(); child != null; child = child.getNextSibling()) {
    if (child instanceof Element) {
        if (((Element) child).getTagName().equals(name)) {
            return true;
return false;
...
booleanhasChildren(Element e)
has Children
if (e == null)
    return false;
return e.getFirstChild() != null;