Home Forums General XMetaL Discussion node list issues/questions Reply To: node list issues/questions

Derek Read

Reply to: node list issues/questions


Here's your original, rewritten:

[code]ActiveDocument.FormattingUpdating = false;
var rngText = ActiveDocument.Range;
foundTagsList = ActiveDocument.getElementsByTagName(“draft-comment”);
while (foundTagsList.length > 0){
element = foundTagsList.item(0);
//convert the node into a selection (using Range)
//get the node's contents w/o containing tags
if (rngText.CanChange(“note”)) {
rngText.ContainerName = “note”;
ActiveDocument.FormattingUpdating = true;[/code]

I've compared the length of time it takes to run both on the same document (an extreme case containing 1,000 draft-comment elements). The simplified version that does not use getElementsByTagName runs about 18% faster (13.6 seconds vs 11.1 seconds) and so not a big difference. For a much shorter and smaller document (which if this is DITA is almost certain to be the case) it would probably not be noticeable.

Looking at it again though, I don't think there's much point in doing the CanChange check. If the call to setting the ContainerName (used to change the element) was to fail then the nodelist would not get any smaller and so the loop would never finish (either as a while or a for loop). I think using this logic you'd probably want to bail out of the loop instead (if there is a possibility of failure) or it would need to be rewritten.