How to get nodes xpath

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

How to get nodes xpath

Post 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();
Bogdan Dumitru
Site Admin
Posts: 172
Joined: Tue Mar 20, 2018 5:28 pm

Re: How to get nodes xpath

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