General XMetaL Discussion

  • edporterIII

    Read-only PI

    Participants 0
    Replies 1
    Last Activity 6 years, 11 months ago

    I'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]

    Reply

    Derek Read

    Reply to: Read-only PI

    If 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.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support