General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion ActiveDocument.doctype returns empty string

  • ApoY2k

    ActiveDocument.doctype returns empty string

    Participants 4
    Replies 5
    Last Activity 8 years, 6 months ago

    I have a document which uses a doctype definition with some custom entities as follows:

    [code] 
      “>
      “>
     
    ]>[/code]

    When using ActiveDocument.doctype.publicId to get the DTD name (-//DTD Operating Instructions Authoring//EN), instead I get an empty string returned. Why is that and how can I get the actual public id of the DTD?

    PS: Using XMetaL 7.0.0.111

    Reply

    Derek Read

    Reply to: ActiveDocument.doctype returns empty string

    I don't have ready access to a 7.0 installation at this moment but I don't see this issue with 8.0.1.051 or 9.0.0.024 (current release).

    Pasting the following script snippet into the sample “Cameras In Focus (Journalist)” returns the PUBLIC id for me. I've modified the sample to include your subset.

    [code]//XMetaL Script Language JScript:
    Application.Alert(ActiveDocument.doctype.publicId);[/code]

    My document:
    [code]
     
      “>
      “>
     
    ]>

      Focus On Digital Cameras
    …etc…[/code]

    Which event are you using this API inside of? That may be part of the issue.

    Reply

    ApoY2k

    Reply to: ActiveDocument.doctype returns empty string

    I use it in a On_Document_Save Macro. I also used in another project in a On_Document_Activate, where it worked fine…

    What else could cause the publicId to be empty?

    I just had some tries that made things even worse: I now have two scripts, one on document save and one on document deactivate. Now, when I view the file in XML/Text mode, save it, the publicId is empty, as well as when I close the document out of XML/Text view.

    But, when I edit the file in Normal view or in Tag view, both scripts (save and deactivate) return the publicId just fine. It's only if I edit it in Text view that the public Id returns empty.

    Reply

    Derek Read

    Reply to: ActiveDocument.doctype returns empty string

    This API and many others cannot be used in Plain Text view. There is no XML DOM when viewing documents in Plain Text view so any APIs that return information about the schema or the XML DOM will fail or return nothing.

    The DOM is only available in Tags On view and Normal view. It is created when you load a document from file into one of those views or when you switch from Plain Text view into one of those views.

    If you need to know what this value is for a script running in Plain Text view you will need to find it via some other means. Perhaps you could store it when the view is in Tags On or Normal view. If not then you may need to parse the XML as a string to locate it or load the XML into an external XML parser or through some other means.

    Reply

    ApoY2k

    Reply to: ActiveDocument.doctype returns empty string

    I had a talk with the customer and he said the authors will only use the normal view anyway, so my “problem” is not applicable.

    Thanks for the clarification 🙂

    Reply

    Derek Read

    Reply to: ActiveDocument.doctype returns empty string

    If Plain Text view is enabled (it is unless you or some other customization has called DisablePlainTextView <- several CMS integrations do this) just make sure you wrap your code in an if block that checks the ViewType. Something like this:
    [code]
    if(ActiveDocument.ViewType < 2) {
      //run my code
    }
    else {
      //don't run my code
    }[/code]

    Reply

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

Lost Your Password?

Products
Downloads
Support