I have been trying to get the full path to a node. the selectnodes is always giving undefined. Am I doing anything wrong? or is thee another way to get full xpath for a node using GetContextNodes(). Please help! Urgent.
function AddComment_onclick() {
//here get the conext
// More than one item may be selected in the form, such as multiple table rows...
// Just get the first item (zero-based).
var oFocusNode = goXDocument.View.GetContextNodes().Item(0);
// Build the XPath to the focus field.
// This will be used to identify a matching XPath in the Help DOM.
var sXPath = "";
var oPathNode = oFocusNode
sXPath = GetXPath_SequentialIteration(oPathNode);
alert(sXPath);
}
function GetXPath_SequentialIteration(node)
{
try
{
var path;
path = "/" + node.baseName;
alert(path);
pNode = node.parentNode;
if (pNode != null) {
// Gets the position within the parent element.
// However, this position is irrelevant if the element is unique under its parent:
var siblings = pNode.SelectNodes(node.baseName);
alert("Siblings " + siblings.length);
if (siblings != null && siblings.length > 1) // There's more than 1 element with the same name
{
var position = 1;
for (i = 0; i < siblings.length; i++)
{
if (i == node)
{
break;
}
position++;
}
path = path + "[" + position + "]";
}
// Climbing up to the parent elements:
path = pNode.GetXPath_SequentialIteration() + path;
}
}
catch (e) {
// Currently we don't handle any exceptions.
// But we also don't want an error to appear if there is one.
alert(e.Description);
}