Page 1 of 1

How to get nodes xpath

Posted: Wed Dec 14, 2022 11:29 am
by shilpa
Hi Team,

Below is the example where i need xpath of para node including its parents.

Ex ;
<footnote>
<footnote.body>
<para> Testing the xpath
</para>
</footnote.body>
</footnote>


in the above xml say i have clicked in para so now i need the path where my cursor placed. Below is the result which i need. Please let me know how to achieve this using javasript.
//footnote/footnote.body/para
Using below code i am getting tag name where my cursor placed like para but i want whole parent xpath as well.
let selection = jaEditor.getSelectionManager().getSelection();
let tagName = selection.getNodeAtSelection().getNodeName();

Re: How to get nodes xpath

Posted: Wed Dec 14, 2022 2:10 pm
by Bogdan Dumitru
Hello Shilpa,

By "but i want whole parent xpath as well" do you mean that you want to access the parent nodes of the node at caret?
If yes, note that you can use the "parentNode" property like this:

Code: Select all

var nodeAtSelection = editor.getSelectionManager().getSelection().getNodeAtSelection();
var parentTagName = nodeAtSelection.parentNode.tagName;
See the Document, Element and Node interfaces from our JS API.