Custom validation engines

Post here questions and problems related to oXygen frameworks/document types.
jcb_mgc
Posts: 8
Joined: Thu Sep 10, 2020 7:03 pm

Custom validation engines

Post by jcb_mgc »

We are currently doing some "validation" on othermeta elements in .ditamap files. We are migrating from a Frame/dita-ot/command-line build pipeline. We have a Perl script to perform this check; currently these scripts are launched via Ant.

I have looked at creating a custom validation engine that points at the perl.exe; I associated it with the XML editor. I added it as a validation unit to the DITA Map validation scenario. When I validate the .ditamap file, I get "Perl is not configured to validate with schema type text/dtd".

We also have some custom link checking that we need to add to the validation scenario. This is also written in Perl.

As I read more about validation in oXygen, it seems this type of validation doesn't really fit into the model of validation engines and validation scenarios. It's not actually "validation" in the strict XML/DTD/Schema sense of the word. What we are doing is more of a "pre flight check" for sanity in othermeta settings and links.

I'm looking for some advice on how to implement this. Is there a way to execute Perl in the context of a validation scenario? We need to give it our .pl script and the current .ditamap file as command arguments.

--OR-- is this type of checking better implemented as a oXygen plugin, written in Java? And if we need to go this route, would this action be scriptable?

Thanks,
John
Radu
Posts: 9258
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom validation engines

Post by Radu »

Hi John,

In my opinion you should try to migrate your Perl checks to Schematron rules:

https://blog.oxygenxml.com/topics/SchematronBCs.html

because in an Oxygen validation scenario you can add validation stages which validate the XML document using Schematron.

If you still want to use your custom Perl validation, you will probably need to also build an Oxygen plugin.

An Oxygen Java plugin of type Workspace Access:

https://www.oxygenxml.com/doc/versions/ ... lugin.html

can add a listener which detects when an XML document is opened:

https://www.oxygenxml.com/InstData/Edit ... a.net.URL-

and on the opened "WSEditor" it can add a validation problems filter:

https://www.oxygenxml.com/InstData/Edit ... emsFilter-

That filter can either add new problems (maybe by running an external process and obtaining the errors) or filter out existing errors.
There are two types of validation Oxygen does, manual validation is done when you explicitly press the "Validate" toolbar button and automatic validation is done every time you time. If you choose to present more problems for "automatic validation" your code needs to be quite fast because it will be invoked every time changes are made to the document.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
jcb_mgc
Posts: 8
Joined: Thu Sep 10, 2020 7:03 pm

Re: Custom validation engines

Post by jcb_mgc »

Hi Radu thanks for that info.

I tried implementing one simple check using Schematron rules. The check tests for the existence of an othermeta element in the main .ditamap.

I then added my Schematron file to the Dita Map Validation and completeness check via the "Additional Schematron checks" field at the bottom of the Validation and completeness dialog box.

However, when I run the action on the .ditamap, I see no evidence that my Schematron rule is being used. I purposely introduced an error in the .ditamap file that would trigger the Schematron assertion to fail, and I see no messages or any indication that the .sch file I specified is being used at all.

Is there another step that I am missing?
Thanks,
John
jcb_mgc
Posts: 8
Joined: Thu Sep 10, 2020 7:03 pm

Re: Custom validation engines

Post by jcb_mgc »

Hi Radu please disregard my previous reply --- the XPATH in my rule's context attribute was incorrect. The Schematron check does work as intended, although it seems to be invoking my Schematron checks twice. I.E. I get TWO messages triggered by my the error that I purposely created.

-John
Radu
Posts: 9258
Joined: Fri Jul 09, 2004 5:18 pm

Re: Custom validation engines

Post by Radu »

Hi John,

I'm glad you made progress on this. I'm not sure why the error gets reported twice. I cannot reproduce the problem on my side testing with a small Schematron schema which is triggered when a DITA topic has only one paragraph inside it:

Code: Select all

<schema xmlns="http://purl.oclc.org/dsdl/schematron" 
    queryBinding="xslt2" xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    <pattern id="single_paragraph"
        >
        <rule context="*[contains(@class, ' topic/topic ')]">
            <report
                test="not(*[contains(@class, ' topic/shortdesc ')] | *[contains(@class, ' topic/abstract ')]) 
                           and count(*[contains(@class, ' topic/body ')]/*) = 1 
                           and *[contains(@class, ' topic/body ')]/*[contains(@class, ' topic/p ')]
                           and count(*[contains(@class, ' topic/body ')]/*[contains(@class, ' topic/p ')]/*) = 0"
                role="warning">In cases where a topic contains only one paragraph, then it is
                preferable to include this text in the shortdesc element and leave the topic body
                empty.</report>
        </rule>
    </pattern>
</schema>
Can you maybe post a small Schematron schema which I can use to obtain the doubling of the error message on my side? Did you also associate the Schematron schema directly with the DITA frameowork? Or right now you are only using it from the "Validate and check for completeness" dialog?

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