Android Utililty Methods XML Node Child Check

List of utility methods to do XML Node Child Check


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


booleanhasChild(Node node, String namespace, String name)
Search for availability of a certain child.
return getFirstChild(node, namespace, name) != null;
booleanhasChildElement(NodeList list)
Checks if the given NodeList contains a child element.
Node n;
for (int i = 0; i < list.getLength(); i++) {
    n = list.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        return true;
return false;
booleanhasTextContent(Node child)
has Text Content
return child.getNodeType() != Node.COMMENT_NODE
        && child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
booleanisDescendantOrSelf(Node ctx, Node descendantOrSelf)
Returns true if the descendantOrSelf is on the descendant-or-self axis of the context node.
if (ctx == descendantOrSelf) {
    return true;
Node parent = descendantOrSelf;
while (true) {
    if (parent == null) {
        return false;
    if (parent == ctx) {
        return true;
    if (parent.getNodeType() == Node.ATTRIBUTE_NODE) {
        parent = ((Attr) parent).getOwnerElement();
    } else {
        parent = parent.getParentNode();
booleanisInstance(Node node, String namespace, String name)
Test if a node matches a namespace/name criteria, handling a null as match any.
if (node.getNodeType() != Node.ELEMENT_NODE) {
    return false;
if (namespace != null && !namespace.equals(node.getNamespaceURI())) {
    return false;
if (name != null && !name.equals(node.getLocalName())
        && !name.equals(node.getNodeName())) {