Home Forums General XMetaL Discussion Get nodelist from Selection/Range? Reply To: Get nodelist from Selection/Range?

Derek Read

Reply to: Get nodelist from Selection/Range?

This is very likely incomplete but you might build on it. There are probably test cases I have not thought of.
If you want to capture other types of nodes (text, comment, PI, etc) then this would probably need to be substantially rewritten.

[code]//XMetaL Script Language JScript:
//debugger;
var nodes = Array();
var rngS = ActiveDocument.Range;
var rngE = rngS.Duplicate;
rngS.Collapse(sqCollapseStart);
rngE.Collapse(sqCollapseEnd);
var i = 0;
rngS.MoveToElement();
while(rngS.IsLessThan(rngE,false)) {
if(rngS.ContainerNode.nodeType == 1) {
nodes = rngS.ContainerNode;
i++;
}
if(rngS.MoveToElement() == false) {
break;
}
}

var msg = “”;
for(i=0;i msg += nodes
.nodeName + “n”;
}
Application.Alert(msg);[/code]

Reply

Products
Downloads
Support