Find the Ancestor Parent

Having trouble installing Oxygen? Got a bug to report? Post it all here.
shilpa
Posts: 66
Joined: Mon Jul 04, 2022 8:42 am

Find the Ancestor Parent

Post 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>
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Find the Ancestor Parent

Post 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
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply