How to access the failed xsd 1.1 assert rule during validation?

核能气质少年 提交于 2021-02-05 07:25:27

问题


I hope I am not asking a stupid question but I was unable to find an answer myself yet.

Situation:

I have a xml file which has to be validated against an XSD 1.1 (with a lot of asserts). For the validation I use this xerces version: org.opengis.cite.xerces:xercesImpl-xsd11:2.12-beta-r1667115.

As it has been stated quite a few times on Stackoverflow, this seems to be the only working version for XSD 1.1. And yes, it works perfectly.

After the validation, I need to know every single violation of an assert rule, as (in my use case) they only hint towards some statistical issues which should be reported to the user afterwards.

I rewrote the error handler to gather all the rule breaking occurences during the run.

In the XSD files a rule looks like this:

<xs:assert test="if(SVDUSCHENBADEN/@value = (2,3) and (SVOBERKOERPER/@value = 0 or SVKOPF/@value = 0 or SVINTIMBEREICH/@value = 0)) then false() else true()">
            <xs:annotation>
                <xs:appinfo>
                    <das:rule_id value="70011"/>
                    <das:rule_text value="Hinweis: Für das Datenfeld 'Duschen oder Baden einschließlich Waschen der Haare' ist [2] = 'überwiegend unselbständig' oder [3] = 'unselbständig' und für eines der Datenfelder 'Waschen des vorderen Oberkörpers','Körperpflege im Bereich des Kopfes' oder 'Waschen des Intimbereichs' ist [0] = 'selbständig' angegeben (Die Angaben können zu einer Auffälligkeit in der statistischen Plausibilitätsprüfung führen)"/>
                    <das:rule_type value="WARNING"/>
                    <das:rule_fields>
                        <das:field value="SVDUSCHENBADEN"/>
                        <das:field value="SVINTIMBEREICH"/>
                        <das:field value="SVKOPF"/>
                        <das:field value="SVOBERKOERPER"/>
                    </das:rule_fields>
                </xs:appinfo>
            </xs:annotation>
        </xs:assert>

I was expecting (in my naivety) that I would have access to e.g. the value of "das_rule_text" during the error handling of the validation run, but I only get a column and line number of the closing tag where the error ocurred and a preset error message like this:

cvc-assertion: Assertion evaluation ('if(SVDUSCHENBADEN/@value = (2,3) and (SVOBERKOERPER/@value = 0 or SVKOPF/@value = 0 or SVINTIMBEREICH/@value = 0)) then false() else true()') for element 'qs_data' on schema type 'das_qs_data_type' did not succeed.

Is there a way to read the contens of the XSD rule during validation ? Or afterwards ? Am I completely off the rails or do I miss something obvious here ?

Please, help me to find the right direction.

Bye, Torsten...


回答1:


Sorry to disappoint you. The entire XSD fragment in question is for documentation purpose only. It exists for humans only.

It is however possible to, specify an user-defined error message for assertion failures. In Xerces via xerces:message attribute. [How to specify a user defined error message, when an XML Schema 1.1 assertion returns a 'false' result?]1

XSD fragment

<xs:annotation>
    <xs:appinfo>
        <das:rule_id value="70011"/>
        <das:rule_text value="Hinweis: Für das Datenfeld 'Duschen oder Baden einschließlich Waschen der Haare' ist [2] = 'überwiegend unselbständig' oder [3] = 'unselbständig' und für eines der Datenfelder 'Waschen des vorderen Oberkörpers','Körperpflege im Bereich des Kopfes' oder 'Waschen des Intimbereichs' ist [0] = 'selbständig' angegeben (Die Angaben können zu einer Auffälligkeit in der statistischen Plausibilitätsprüfung führen)"/>
        <das:rule_type value="WARNING"/>
        <das:rule_fields>
            <das:field value="SVDUSCHENBADEN"/>
            <das:field value="SVINTIMBEREICH"/>
            <das:field value="SVKOPF"/>
            <das:field value="SVOBERKOERPER"/>
        </das:rule_fields>
    </xs:appinfo>
</xs:annotation>

Custom error message in Saxon

<xs:assert test="if ((count(r[DeviceCost = 0]) div count(r)) le 0.01) then true() else false()"
           saxon:message="Rule #15: Just one percent or less of the DeviceCost values could be zero"
           xpathDefaultNamespace="##targetNamespace">
    <xs:annotation>
        <xs:documentation>Rule #15</xs:documentation>
        <xs:documentation>Just one percent or less of the DeviceCost values could be zero</xs:documentation>
    </xs:annotation>
</xs:assert>


来源:https://stackoverflow.com/questions/60186729/how-to-access-the-failed-xsd-1-1-assert-rule-during-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!