Home Forums General XMetaL Discussion Why is XMetaL unable to locate a text node? Reply To: Why is XMetaL unable to locate a text node?

Derek Read

Reply to: Why is XMetaL unable to locate a text node?

If the answer to my question is “yes” (ie: “you need to find text node # 123 and move the selection to that position in the document”) then you can try something like this:

//XMetaL Script Language JScript:
var textNodeCount = 0;
var rng = ActiveDocument.Range;

function readtree(node,cnt) {
//Do this for text nodes only
if (node.nodeType==3) {
textNodeCount++;
if(textNodeCount == cnt) {
rng.SelectNodeContents(node);
rng.Select();
}
}

// Process this node's children
if (node.hasChildNodes()) {
readtree(node.firstChild,cnt);
}

// Continue with this node's siblings
if (node.nextSibling!=null) {
readtree(node.nextSibling,cnt)
}
}
readtree(ActiveDocument.DocumentElement,123);

Reply

Products
Downloads
Support