Validation Layer with interdependency checks

百般思念 提交于 2019-12-13 09:14:11

问题


Existing backend services will be opened for more clients (adding a Web Service Layer to the Web-Frontend client).
Currently, XML Schema is used for validation of DTOs, but since the frontend is out of our control, we will have to move extended tests (eg. interdependency tests) from the frontend layer to a new "validation layer".
Now our question is if there exist a common pattern for this, eg. something similar to using RELAX NG or a rule engine? The requirement is to be able to check datatypes (we would stay with XML Schema here) and interdependencies, but these interdependencies can get quite complicated, ie. they might involve checks on data which is not available in the input data (but in some external system).
So we are looking for a patterns as well as a framework which makes it easy to implements the patterns.


回答1:


Schematron is the schema language to look at (used as a layer on top of your XSD probably).

Schematron is based around constraints expressed using XPath, which in most cases is powerful enough to express what is needed. Since XPath can be extended with user-defined functions, there is scope to be able to carry out potentially any validation by e.g. comparing data from external databases etc.

(If you are drawing on data outside your document for validation purposes a nice approach is to expose that external data as XML - perhaps available in a RESTy fashion - so the validation constraints can be expressed entirely in XML terms within your Schematron schema.)



来源:https://stackoverflow.com/questions/4050855/validation-layer-with-interdependency-checks

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