List of utility methods to do XML Has Child
boolean | hasChildElements(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; ... |
boolean | hasChildElements(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; ... |
boolean | hasChildElementWithAttribute(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; ... |
boolean | hasChildNode(Element root, String childNodeName) has Child Node NodeList nl = root.getElementsByTagName(childNodeName);
return (nl.getLength() > 0);
|
boolean | hasChildNode(Node parentNode, String nodeName) Determine if the parent node contains a child node with matching name return getChildNode(parentNode, nodeName, null) != null ? true : false;
|
boolean | hasChildNodeByName(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(); ... |
boolean | hasChildNodes(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;
|
boolean | hasChildNS(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; |
boolean | hasChildOfType(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; ... |
boolean | hasChildren(Element e) has Children if (e == null) return false; return e.getFirstChild() != null; |