XML validation with Schematron/XSD in C#

后端 未结 1 1202
别那么骄傲
别那么骄傲 2021-01-11 14:48

I\'ve been looking around for at a way to make some more advanced business rule validation of XML documents. So far Schematron seems to be able to do, what I need.

相关标签:
1条回答
  • 2021-01-11 15:24

    For what it's worth, this has been my experience...

    I've had moments where I wish schemas could do more along the lines of business rule validation. However, in my experience a schema is there to define a data contract (format, types, etc)... NOT to enforce business rules. Trying to make it more than that runs into all sorts of problems and may be why Schematron seems to have died down in its popularity (possibly bad assumption that I cannot backup).

    To get around this, one can generally do a two pass approach:

    • Validate the xml structure/data types, etc using schema validation.
    • Apply business rules checking against the xml (in normal c# code).

    I understand if you're wanting to do an all-in-one approach to validation but attempting to use schema for this causes more headaches in the long run. In the end you'll end up having finer control over your business rule checking by isolating to code.

    0 讨论(0)
提交回复
热议问题