Here you can find the source of isDescendantOrSelf(Node ctx, Node descendantOrSelf)
Parameter | Description |
---|---|
ctx | a parameter |
descendantOrSelf | a parameter |
public static boolean isDescendantOrSelf(Node ctx, Node descendantOrSelf)
//package com.java2s; /* NOTICE: This file has been changed by Plutext Pty Ltd for use in docx4j. * The package name has been changed; there may also be other changes. * /*from www . j a v a 2 s . c o m*/ * This notice is included to meet the condition in clause 4(b) of the License. */ import org.w3c.dom.Attr; import org.w3c.dom.Node; public class Main { /** * Returns true if the descendantOrSelf is on the descendant-or-self axis * of the context node. * * @param ctx * @param descendantOrSelf * @return true if the node is descendant */ public static boolean isDescendantOrSelf(Node ctx, Node descendantOrSelf) { 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(); } } } }