2 Replies Latest reply on Feb 6, 2014 12:42 PM by workingmike

    How can I autorun a script that will process an XML file on open?


      I am using Frame 11. I have a registered script that looks for event notification Constants.FA_Note_PostOpenXML. When this event fires, the script is supposed to examine the root element (so I only edit appropriate XML files), then make some edits to the file. Specifically, I want to be able to delete empty pages, remove room for side heads, and fix table formatting (such as left indent, which I can't directly access, apparently, in the EDD or R/W rules). The snippet of code that starts doing the work follows:



      function Notify(note, object, sparam, iparam) {

          switch (note) {

              case Constants.FA_Note_PostOpenXML:





      function doTheWork() {

          var doc, flow, root, elemName, mPageAttrib, topicElem, topicElemName, allAttribs;

          doc = app.ActiveDoc;

          flow = doc.MainFlowInDoc;

          root = flow.HighestLevelElement; // will always get something even if unstructured document

          while(root.ObjectValid()) { //only do something for structured docs

              elemName = getElementName(root);

              ...more code to do stuff....




      I then check the root element name, and if it matches, I make some changes. This code works fine when run manually. But, when run as a registered script, the app.ActiveDoc object is invalid, and there is no structure to edit. (I added debug line if(!doc.ObjectValid()){alert("not valid");}, which is not included above.) It appears that the Constants.FA_Note_PostOpenXML event fires as soon as the XML file is opened, but BEFORE Frame actually reads it.


      Does anyone have any recommendations on how to work around this? Is there another event I could use instead of Constants.FA_Note_PostOpenXML? Is there any other way to automatically manipulate an XML file when it loads?

      Thanks in advance