On 8/11/22 14:53, Madlik, Monika (LNG-VIE) wrote:

we are using XMLMind Professional Edition 9.5.1 and I have a question regarding 
files that have no DTD but should have one.

I have to add a DTD to these files. Is it possible to write a command that 
saves the currently opened file, adds a dtd (maybe via xslt transformation?) 
and reloads it in XMLMind, so that the user works on the latest version of this 
file?


The answer is almost certainly YES, but it will not be easy because there is an awful lot of XXE techniques to master.

We won't help you writing or debugging such advanced macro-command (probably invoking a process command) as it is completely out of the scope of normal support.

Some pointers though...

1) The following command is found in XXE_install_dir/config/addon/docbook/docbook.xxe.

It converts the currently DocBook v4.x document to v5.0 or v5.1 by (A) invoking a XSLT stylesheet called "db4-upgrade.xsl" (part of the DocBook XSL stylesheet distribution) and then (B) opening in XXE the resulting DocBook v5 file using command "XXE.open":

---
<command name="docb.toV5">
  <macro>
    <sequence>
<set variable="converted" expression="uu:setExtension('%d', 'db5.xml')"
           xmlns:uu="java:com.xmlmind.util.URIComponent" />

      <get expression="$converted" />
      <command name="selectFile"
               parameter="[DocBook 5 Save File] saveFileURL %_" />
      <set variable="converted" expression="%_" plainString="true" />

      <choice>
        <sequence>
          <test expression="$converted = '%d'" />
          <command name="alert"
parameter="Please specify a save file other than&#xA;%d" />
        </sequence>

        <sequence>
          <command name="pick"
                   parameter="'Which DocBook version?'
                              false '&quot;5.0&quot;' '&quot;5.1&quot;'" />
          <set variable="params"
               expression="concat('&quot;', $converted, '&quot; ', %_)" />

          <get expression="$converted" />
          <command name="XXE.saveAs" parameter="%_" />

          <get expression="$params" />
          <command name="{docb}.convertToV5" parameter="%_" />

          <command name="XXE.open" parameter="[reopen]" />
        </sequence>
      </choice>
    </sequence>
  </macro>
</command>

<command name="{docb}.convertToV5">
  <process showProgress="true">
    <copyDocument preserveInclusions="true" to="in.xml">
      <!-- Do not copy resources. -->
      <resources match=".*" />
    </copyDocument>

    <transform stylesheet="db4-upgrade.xsl" cacheStylesheet="true"
               file="in.xml" to="out.xml">
      <parameter name="db5.version">%1</parameter>
    </transform>

    <upload base="%0">
      <copyFile file="out.xml" to="%0" />
    </upload>
  </process>
</command>
---

2) Relevant documentation:

- Macro-commands: http://www.xmlmind.com/xmleditor/_distrib/doc/commands/macro.html

- Process commands: http://www.xmlmind.com/xmleditor/_distrib/doc/commands/process.html

- Command "XXE.open": http://www.xmlmind.com/xmleditor/_distrib/doc/commands/XXE.open.html

- Easy XPath extension functions (e.g "uu:setExtension"): http://www.xmlmind.com/xmleditor/_distrib/doc/xpathsupport/xpathextfunc_java.html





--
XMLmind XML Editor Support List
xmleditor-support@xmlmind.com
http://www.xmlmind.com/mailman/listinfo/xmleditor-support

Reply via email to