Java Utililty Methods XML Node Parent

List of utility methods to do XML Node Parent

Description

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

Method

booleanisAnyNodeAncestorOf(ArrayList ancestorNodes, Node node)
Checks if any of from the given list of nodes is an ancestor to another node
int n = ancestorNodes.size();
for (int i = 0; i < n; i++) {
    Node ancestor = (Node) ancestorNodes.get(i);
    if (isAncestorOf(ancestor, node)) {
        return true;
return false;
...
booleanisDescendant(Node test, Node target)
is Descendant
Node parent = test.getParentNode();
if (parent == null)
    return false;
else if (parent.equals(target))
    return true; 
return isDescendant(parent, target);
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();
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();
ElementpreviousSiblingElement(Node node)
previous Sibling Element
for (Node tempNode = node.getPreviousSibling(); tempNode != null; tempNode = tempNode
        .getPreviousSibling()) {
    if (tempNode.getNodeType() == Node.ELEMENT_NODE) {
        return (Element) tempNode;
return null;
voidresolveLeafNodeValue(Node node)
resolve Leaf Node Value
if (node != null) {
    Element element = (Element) node;
    NodeList childNodeList = element.getChildNodes();
    for (int j = 0; j < childNodeList.getLength(); j++) {
        Node chileNode = childNodeList.item(j);
        if (!chileNode.hasChildNodes()) {
            String nodeValue = resolveSystemProperty(chileNode.getTextContent());
            childNodeList.item(j).setTextContent(nodeValue);
...