How do I return Schematron validation results in a structured manner

牧云@^-^@ 提交于 2019-12-19 09:24:09

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/5902349/how-do-i-return-schematron-validation-results-in-a-structured-manner

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