How do I return Schematron validation results in a

2020-03-25 08:47发布

I have created several Schematron assertations and they are all running fine against my XML instances. However, I would like to structure the output of my error messages in such a way, that I later can post-process them, with e.g., Java.

The output of my assertion error message should be

<error>
  <errorMessage>My error message</errorMessage>
  <violatingElement>The violating element</violatingElement>
</error>

However, a construct such as:

<pattern>
  <rule context="/p1:Document/p1:Delivery/p1:DeliveryDetails/p1:ShippingDate">
    <report test=".">
      <error>
       <errorMessage>My error message</errorMessage>
       <violatingElement>The violating element</violatingElement>
      </error>
    </report>
 </rule>
</pattern>

does not work. What is the correct way of returning Schematron results in a structured (XML-ified) manner?

3条回答
家丑人穷心不美
2楼-- · 2020-03-25 09:07

Actually to get a Schematron report as XML you should use SVRL. You can learn more about it here: Schematron Validation Report Language (SVRL)

The big advantage of using SVRL is that you can also get detailed information about where the assertion/report was triggered as an XPath.

查看更多
姐就是有狂的资本
3楼-- · 2020-03-25 09:22

You can also leverage a native schematron engine, rather than an XSL stylesheet, to deteremine whether the assertions are satisfied. I'm working with one for .NET / C# here.

查看更多
Rolldiameter
4楼-- · 2020-03-25 09:25

Schematron by design wants to keep the content of assertions and reports as natural language only. The Standard (available here) encourages the use of the diagnostics element for richer information. It states:

The natural-language assertion may contain information about actual values in addition to expected values and may contain diagnostic information. Users should note, however, that the diagnostic element is provided for such information to encourage clear statement of the natural-language assertion.

diagnostic messages are contained in <diagonstic> elements (wrapped in a <diagnostics> wrapper) and associated with reports and assertions using an ID/IDREF mechanism.

There is an example showing the use of diagnostics in Annex G of the Standard.

查看更多
登录 后发表回答