Pages: 1
Print
Author Topic: ActiveDocument.doctype returns empty string  (Read 2822 times)
ApoY2k
Member

Posts: 3


« on: March 12, 2014, 08:27:29 AM »

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

Code:
<!DOCTYPE Registration PUBLIC "-//DTD Operating Instructions Authoring//EN" "Registration.dtd"[
  <!-- Begin Document Specific Declarations -->
  <!ENTITY PRO01 ">">
  <!ENTITY TM_SSC ">">
  <!-- End Document Specific Declarations -->
]>

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
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: March 12, 2014, 11:49:45 AM »

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);

My document:
Code:
<?xml version="1.0"?>
<!DOCTYPE Article PUBLIC "-//SoftQuad Software//DTD Journalist v2.0 20000501//EN" "../../Rules/journalist.dtd"[
  <!-- Begin Document Specific Declarations -->
  <!ENTITY PRO01 ">">
  <!ENTITY TM_SSC ">">
  <!-- End Document Specific Declarations -->
]>
<Article>
  <Title>Focus On Digital Cameras</Title>
...etc...

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

Posts: 3


« Reply #2 on: March 13, 2014, 01:56:08 AM »

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.
« Last Edit: March 13, 2014, 02:18:34 AM by ApoY2k » Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #3 on: March 13, 2014, 05:26:49 PM »

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.
Logged
ApoY2k
Member

Posts: 3


« Reply #4 on: March 14, 2014, 09:14:53 AM »

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 :-)
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #5 on: March 14, 2014, 01:55:31 PM »

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
}
Logged
Pages: 1
Print
Jump to:  

email us