本文介绍了XML验证使用的Schematron / XSD在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在四处寻找的一种方法,使XML文档的一些更高级的业务规则验证。到目前为止Schematron的似乎是能够做到的,我需要什么。

我一直在环顾四周,我发现了一些库是很旧,似乎不支持任何更长的时间。当时的Schematron在2002年,只有热?是否有可以做在C#中验证的库 - ?或者我怎么办呢

还是有其他人,可以做先进的验证和有C#库和标准化?

解决方案

有关它的价值,这一直是我的经验...

我已经时刻,我希望的模式可以做更多的沿业务规则验证线。然而,在我的经验,模式是有定义一个数据的合同(格式,类型等)... 不会以执行业务规则。试图使其更重要的是运行到各种各样的问题,可为什么Schematron中似乎已经在它的普及平息后(可能是坏的假设,我不能备份)。

要解决这个问题,我们可以大致做一个双通道的方法:

  • 验证XML架构/数据类型等使用模式验证。
  • 在应用业务规则检查,对XML(可在普通的C#code)。

据我所知,如果你想要做一个全功能于一身的方法来验证,但尝试使用架构这将导致更多的麻烦,从长远来看。最后,你会最终不得不被隔离至code在您的业务规则检查更精确的控制。

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.

I've been looking around, and the few libraries I've found was very old and seemingly not supported any longer. Was Schematron only "hot" in 2002?Are there any libraries that can do the validation in C# - or how do I do it?

Or are there others that can do the advanced validation and have C# libraries and are standardized?

解决方案

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.

这篇关于XML验证使用的Schematron / XSD在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:22