General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion get processing instruction node after xml declaration tag

  • akheiljain

    get processing instruction node after xml declaration tag

    Participants 2
    Replies 3
    Last Activity 10 years, 5 months ago

    I have an xml document and need to update the processing instruction, On_Document_Open_Complete macro.

    Before



    After


    I am unable to select the processing instruction node.
    Tried
    var nodeSelect = ActiveDocument.getNodesByXPath(“/processing-instruction('dctm')”)
    Application.Alert(nodeSelect.length)
    returns 0

    Reply

    Derek Read

    Reply to: get processing instruction node after xml declaration tag

    You cannot modify nodes outside the root element while in Tags On or Normal view, they just are not accessible.

    You have a few options I can think of:
    1) Use the event On_Application_Before_Document_Open and 3rd party software to modify the file before it is opened.
    2) In On_Document_Open_Complete switch to Plain Text view before making the modification. Note that in that view you do not have access to a DOM (it doesn't exist) so your options for interacting with the document are basically limited to manipulating text (as a use might) though you can use Selection and Find.Execute or you could load the whole file into a string and use JScript regular expression to do the replacement.

    It looks like you are working with Documentum. If that is the case I would be wary of messing with files at this level as “XMetaL Author Enterprise for Documentum Webtop” (our integration with Documentum) may not like it if you mess with documents at this level.

    Reply

    Derek Read

    Reply to: get processing instruction node after xml declaration tag

    Under normal circumstances (with an installation that has not had “application-level” macros altered) what I said previously is correct.

    However, it is possible to move a Range object outside the root element provided you make modifications to the xmetal.mcr file inside the Macros folder in the installation. In that file there's an On_Update_UI event macro that forces the user's selection to stay inside the root element. Disabling that event should allow a Range to get to the PI.

    I would warn against doing this however, unless you do not mind your user's putting PIs and Comments outside the root. XMetaL will still enforce “rules checking” so that elements are not allowed there.

    Here's some code that will do what you are asking, provided that event macro is disabled. The way I've written this also assumes the PI is visible (not hidden by CSS) because it assumes the user's selection will be placed there at document open.

    //XMetaL Script Language JScript:
    var rng = ActiveDocument.Range;
    if(rng.ContainerName == ".PROCINS") {
    rng.SelectContainerContents();
    if(rng.Text == 'dctm xml_app="Ignore"') {
    Application.Alert(rng.Text);
    rng.Text = 'dctm xml_app="XML Application"';
    }
    }

    Perhaps the best place to handle this however is in the Documentum server as it is checked in or out. That should be far safer than changing this application-level macro and manipulating the document at this level on the XMetaL side. If you need assistance with that you can contact EMC.

    Reply

    Derek Read

    Reply to: get processing instruction node after xml declaration tag

    Here's a version that does what I suggested in item 1 from my initial reply:

    try {
    var cwUtil = new ActiveXObject("CWUtil.StringUtil");
    }
    catch(e) {
    Application.MessageBox("Could not access cwUtil. Problem in On_Application_Before_Document_Open event.",48);
    return;
    }
    //put file that is about to be opened into a string
    //this works because the event this script is in runs before any of XMetaL's "open for edit" logic runs
    var filepath = Application.OpenFileName;
    var xmldoc = Application.FileToString(filepath);
    //string replacement to find first occurrence of the PI in the doc, if there are more then a regex would be needed
    var xmlnew = xmldoc.replace('','');
    //write the new version of the file over top of the old one
    //once that's done XMetaL should (in theory) open the modified version of the file
    cwUtil.StringToUTF8File(xmlnew, filepath);
    cwUtil = null;
    } changeDCTMpi(); ]]>

    I would do this over making changes to macros.mcr or any other additional application-level modifications. However, I still think the best place to handle this type of thing is in the CMS given that this appears to be a PI that Documentum is either setting or that it at least knows about.

    I have not tested this with “XMetaL Author Enterprise for Documentum Webtop”.

    Note that CWUtil is an undocumented control that ships with XMetaL Author Enterprise. Use with caution. As it is used here it could easily be replaced by the standard Windows FSO (File System Object).

    Reply

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

Lost Your Password?

Products
Downloads
Support