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

booleanhasNamedChild(Element e, String name)
has Named Child
Element c = getFirstChild(e);
while (c != null && !name.equals(c.getLocalName()) && !name.equals(c.getNodeName()))
    c = getNextSibling(c);
return c != null;
booleanhasNonWhitespaceChildren(Element element)
check, if the passed element node has non-whitespace children.
if (element.hasChildNodes()) {
    NodeList children = element.getChildNodes();
    int len = children.getLength();
    Node n = null;
    for (int i = 0; i < len; i++) {
        n = children.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
            return true;
...
booleanhasOnlyTextChildNodes(final Node node)
Checks if the given node has only text children.
boolean result = true;
final NodeList children = node.getChildNodes();
for (int i = 0; result && i < children.getLength(); i++) {
    final Node child = children.item(i);
    if (child.getNodeType() != Node.TEXT_NODE) {
        result = false;
return result;
booleanhasOnlyTextChildren( Node node)
has Only Text Children
Node childNode = node.getFirstChild();
while (childNode != null) {
    if (!(childNode instanceof Text)) {
        return false;
    childNode = childNode.getNextSibling();
return true;
...
booleanhasTextChildNodesOnly(Node node)
True if the node has text child elements only
NodeList nodeList = node.getChildNodes();
if (nodeList.getLength() == 0)
    return false;
for (int i = 0; i < nodeList.getLength(); i++) {
    Node acksToChildNode = nodeList.item(i);
    if (acksToChildNode.getNodeType() != Node.TEXT_NODE)
        return false;
return true;