問題描述
我一直在尋找一種方法來對 XML 文檔進行一些更高級的業務規則驗證.到目前為止,Schematron 似乎能夠做到,我需要什么.
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.
我一直在環顧四周,發現的幾個庫都非常老舊,似乎不再受支持.Schematron 在 2002 年只是熱"嗎?是否有任何庫可以在 C# 中進行驗證 - 或者我該怎么做?
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?
或者還有其他可以進行高級驗證并擁有 C# 庫并進行標準化的嗎?
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...
我曾經希望架構可以在業務規則驗證方面做得更多.但是,根據我的經驗,有一個模式來定義數據協定(格式、類型等)...... 不 來強制執行業務規則.試圖讓它變得更多會遇到各種各樣的問題,這可能就是為什么 Schematron 的受歡迎程度似乎已經下降(可能是我無法備份的錯誤假設).
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:
- 使用架構驗證驗證 xml 結構/數據類型等.
- 對 xml 應用業務規則檢查(在普通 c# 代碼中).
我了解您是否希望采用一體化的方法進行驗證,但從長遠來看,嘗試為此使用架構會導致更多的麻煩.最后,您將通過隔離代碼來更好地控制業務規則檢查.
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.
這篇關于在 C# 中使用 Schematron/XSD 進行 XML 驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!