How can I use other/more modern schema validation with .Net?
I'm trying to do some work with C# and XML in a cross-platform app (most development is in MonoDevelop on Linux, but most users will end up using the WinForms front-end that I make in Visual Studio). Mono is behaving as I'd expect, but .Net isn't and so I'm looking for options and alternatives.
The schemas have various optional elements followed by an "xs:any" element. This works perfectly fine in Mono, but not in Microsoft's .Net as it complains that the occurrence of the optional element is ambiguous between its actual definition in the schema and "xs:any". From a bit of reading up, it appears to be a problem that was resolved in later versions of W3C's Schema definition. Obviously Mono has been kept up to date, but Microsoft are lagging.
The options I can see are:
1) Use RelaxNG - unfortunately the link from the main site to the C# implementation is broken. It is part of Mono, but that isn't much help when running on MS' .Net. The only way I can see to do it is to duplicate and rebuild Mono's version as my own DLL
2) Use Schematron - I found it as a suggestion on making backward and forward compatible XML, but it seems more like a format validator than a 'standard' schema language. I'm not quite sure where the implementation is - all I can find is a command-line validator.
3) Make sure that the MS .Net implementation uses the updated schema standard that Mono uses as well - I don't even know if this is possible.
4) Stick with ugly schemas and put "xs:any" within an optional "extensions" element - it nests it for no good reason other than the official .Net framework doesn't get confused, but it works.
The code is aimed at .Net 2.0, but I've got 3.5 installed on my machine. I'm also working with Mono 2.4, MonoDevelop 2.2 and Visual Studio Express 2005.
Are any of 1-3 possible, or am I stuck with 4?
Thanks.
You may be able to work around the ambiguity problem by setting the XmlSchemaSet.CompilationSettings.EnableUpaCheck
to false. UPA
stands for the Unique Particle Attribution requirement of the XML Schema standard that you referenced.
I contributed to a resurrection of an ISO schematron implemented in C#. It's available on github here.
链接地址: http://www.djcxy.com/p/44984.html上一篇: 队列的同步