General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Read-only PI
-
edporterIII October 5, 2015 at 3:37 pm
Read-only PI
October 5, 2015 at 3:37 pmParticipants 0Replies 1Last Activity 7 years, 3 months agoI've written the following code to walk a document, and make all of the matching PIs read only. Unfortunately, it appears to be making the container surrounding the PI read-only, rather than the PI itself. Is there a workaround for this?
[code] var uspc = /uspc/i;
var rng = ActiveDocument.Range;
rng.MoveToDocumentStart();var piList = ActiveDocument.getNodesByXPath(“//processing-instruction()”);
for(i=piList.length-1; i>=0; i–) {
rng.SelectNodeContents(piList.item(i));
if(rng.ContainerNode.nodeType == 7 && uspc.test(rng.ContainerNode.target)) {
rng.SelectElement();
Application.Alert(rng.text);
rng.ReadOnly = true;
}
}[/code]Derek Read October 6, 2015 at 9:46 pm
Reply to: Read-only PI
October 6, 2015 at 9:46 pmIf you remove rng.SelectElement() I think you will have something closer to what you want. At the moment your code is affecting the PI's container, not the PI itself.
However, you will also need to change rng.ReadOnly to rng.ReadOnlyContainer because ReadOnly is a read-only property and cannot be set.
But perhaps you want to stop people from removing the PIs? In that case you would use rng.NonRemovableContainer instead.
-
AuthorPosts
- You must be logged in to reply to this topic.