Is there a way to validate external file references?

Post here questions and problems related to editing and publishing DITA content.
mgentry
Posts: 1
Joined: Tue Mar 05, 2024 9:14 pm

Is there a way to validate external file references?

Post by mgentry »

Is there a way in Oxygen to make sure references to external files match an existing filename? For example, if I have a tag:

Code: Select all

<graphic mime-subtype="png" xlink:href="figure6.11-1.png"/>
...I'd like Oxygen to automatically check a specified directory and see if a file named "figure6.11-1.png" actually exists; and if it doesn't, throw up a warning.

Thanks in advance for any tips.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Is there a way to validate external file references?

Post by Radu »

Hi,

You can create a Schematron schema to validate an XML document with custom validation rules.
For example if your XML document looks like this:

Code: Select all

<?xml-model href="test.sch" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<root>
    <graphic mime-subtype="png" href="images/figure6.11-1.png"/>
</root>
you could create a "test.sch" Schematron schema next to it:

Code: Select all

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    <sch:ns uri="java:java.io.File" prefix="java-file"/>
    <sch:ns uri="java:java.net.URI" prefix="java-uri"/>
    <sch:pattern>
        <sch:rule context="*:graphic">
            <sch:assert test="java-file:exists(java-file:new(java-uri:new(resolve-uri(@href))))"> <sch:value-of select="resolve-uri(@href)"/> document should exist.</sch:assert>
        </sch:rule>
    </sch:pattern>
</sch:schema>
In the Oxygen Preferences->"XML / XML Parser / Schematron" page there is a "Disable Schematron security checks" setting which needs to be enabled.
Then you can validate the XML document and the Schematron scheck should be applied on it.
Schematron schemas can also be associated with the XML document using validation scenarios so it is not necessary to refer directly to the Schematron inside the XML file.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply