This below is snippet for it:
if(app.selection[0].constructor.name == "XMLElement" || app.selection[0].constructor.name == "XMLAttribute"){
if(app.selection[0].constructor.name == "XMLAttribute") var node = app.selection[0].parent;
else var node = app.selection[0];
var root = app.documents[0].xmlElements[0];
var tN = node;
var xPath = "";
while(tN != root){
var attr = "/"+tN.markupTag.name;
for(var x = 0; x < tN.xmlAttributes.length; x++){
if(tN.xmlAttributes[x].name.indexOf(":") == -1) attr += "[@"+tN.xmlAttributes[x].name+"='"+tN.xmlAttributes[x].value+"']";
}
tN = tN.parent;
xPath = attr+xPath;
}
xPath = "//"+tN.markupTag.name+"/"+xPath;
var dialog = new Window("dialog");
dialog.text = "Generated Xpath";
dialog.orientation = "column";
dialog.alignChildren = ["right","top"];
dialog.spacing = 10;
dialog.graphics.backgroundColor = dialog.graphics.newBrush (dialog.graphics.BrushType.SOLID_COLOR, [0, 0.251, 0.251]);
var edittext1 = dialog.add('edittext {properties: {name: "edittext1", multiline: true, scrollable: true}}');
edittext1.preferredSize.width = 400;
edittext1.preferredSize.height = 100;
edittext1.text = xPath;
var statictext1 = dialog.add("statictext", undefined, undefined, {name: "statictext1"});
statictext1.text = "Created By Sunil Yadav (Adobe Community Professional)";
edittext1.active = true;
dialog.show();
}
Best
Sunil