Node.js examples for XML:XPath
Determines the xpath from the root node to the clicked node and sets it in the wonder box
/**/* w ww . j a v a 2s . com*/ * Determines the xpath from the root node to the clicked node and sets it in the wonder box * @param ele */ function setXpath(ele) { var wb = document.getElementById('wonderbox'); if (wb) { var path=''; if (ele.className == 'an') { path = '/@'+ele.textContent; } if (ele.className == 'av') { var prevSib = ele.previousSibling; while (prevSib.className != 'an') { prevSib = prevSib.previousSibling; } path = '/@'+prevSib.textContent; } if (ele.className == 'cmt') { path = '/comment()'; } if (ele.className == 'pi') { path = '/processing-instruction()'; } var par = findParentByClassName(ele, 'e'); while (par != null) { path = '/'+ par.firstElementChild.firstElementChild.textContent + path; par = findParentByClassName(par, 'e'); } wb.value=path; } }