Home › Forums › General XMetaL Discussion › Get nodelist from Selection/Range? › Reply To: Get nodelist from Selection/Range?
Reply to: Get nodelist from Selection/Range?
September 12, 2012 at 9:14 pmThis 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
}
Application.Alert(msg);[/code]