General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Collapsing tags containging specific nodes
-
russurquhart1 May 6, 2009 at 4:50 pm
Collapsing tags containging specific nodes
May 6, 2009 at 4:50 pmParticipants 1Replies 2Last Activity 13 years, 8 months agoMe again,
With the code you gave me yesterday:
var nodelist = ActiveDocument.getNodesByXpath(“//*[@filter='filter5']”);
var nodecount = nodelist.length;
Application.Alert(“Fixing ” + nodecount + ” nodes…”);
for (i=0; inodelist.item(0).setAttribute(“filter”, “”);
}Can i collapse the element tag of the specific node at this point, or do i have to somehow convert that to a selection and then call CollapsedContainerTags?
thanks,
Russ
Derek Read May 6, 2009 at 7:16 pm
Reply to: Collapsing tags containging specific nodes
May 6, 2009 at 7:16 pmYes, you will need to convert to a selection and then set CollapsedContainerTags = true
One way (perhaps the best way) to do this would be to:
1. Create a Range object at the start of the script: var rng = ActiveDocument.Range;
2. Inside the for loop move rng to the node in question (before you remove the attribute): rng = nodelist.item(0).SelectContainerContents();
3. Then (also inside the for loop call): rng.CollapsedContainerTags = true;Because this might cause a bunch of flickering as things get redrawn all over the place (this will be more noticeable on slower machines or larger docs) I would suppress any screen formatting updates until everything is done. Something like this:
[code]ActiveDocument.FormattingUpdating = false;
var nodelist = ActiveDocument.getNodesByXpath(“//*[@filter='filter5']”);
var nodecount = nodelist.length;
var rng = ActiveDocument.Range;
Application.Alert(“Fixing ” + nodecount + ” nodes…”);
for (i=0; irng.SelectNodeContents(nodelist.item(0));
rng.CollapsedContainerTags = true;
nodelist.item(0).setAttribute(“filter”, “”);
}
ActiveDocument.FormattingUpdating = true;[/code]russurquhart1 May 6, 2009 at 7:49 pm
Reply to: Collapsing tags containging specific nodes
May 6, 2009 at 7:49 pmThanks for that!
(As i wanted to just collapse the nodes, and in this case not change their attribiute value, the code as it was only changed the first node. Changing the node selected to i, did the trick!)
Thanks again for your help!
Russ
-
AuthorPosts
- You must be logged in to reply to this topic.