Page 1 of 1

Find the Ancestor Parent

Posted: Thu Dec 22, 2022 11:56 am
by shilpa
Hi Team,

I need the ancestor parent of the child node. Please find the below example.

In the below example if my cursor is at any postion i should get parent as disclaimer.

say my cursor is at para of first footnote or second footnote i should get parent as disclaimer.
I am using below methods to get parent but i am getting immediate parent not the ancestor one.
getCommonAncestor();
getStrictCommonAncestor


Please help me on this.

<disclaimer>
<para>
<text.line/>
</para>
<footnote ID=""
xmlns="">
<footnote.body>
<para>
<label.designator/>
</para>
</footnote.body>
</footnote>
<footnote ID=""
xmlns="">
<footnote.body>
<para>
<label.designator/>
</para>
</footnote.body>
</footnote>
</disclaimer>

Re: Find the Ancestor Parent

Posted: Thu Dec 22, 2022 2:42 pm
by mihaela
Hello,

If I understand correctly, you want to obtain the element named "disclaimer", whatever the current position of the caret.
If this is the case I think you should:
- first, get the current element using the AuthorDocumentController.getNodeAtOffset(int), where the offset is the caret offset: authorAccess.getEditorAccess().getCaretOffset()
- if this is not the disclamer element search in parents until you find it.

Also, you can use XPath to search for a specific element: AuthorDocumentController.findNodesByXPath(String, boolean, boolean, boolean, boolean)

Best Regards,
Mihaela