views:

149

answers:

1

Hi,

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.

A: 

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.

binarycoder
In other words, the Microsoft schema validation is telling you about a problem with your schema - it's ambiguous.
John Saunders
<telling you about a problem with your schema> Right, this is definitely a problem with the schema per the current standard. This is loosened in XML Schema 1.1, with the caveat that it is only of "working draft" status.
binarycoder
@binarycoder: and the point is, at Working Draft level, and since it's a different version of the standard, it's unlikely that Mono is implementing the later version of the standard and that Microsoft is behind.
John Saunders
I'll look at that and see if there are any unwanted side-effects. If there are then I guess that leaves me with 4) - adding extra tags around the xs:any just for the sake of it because some of my previous definitions at the same level are optional. Unless anyone has any options on the others.Thanks.
IBBoard
It doesn't seem to be working at the moment. I've just added:`cache.CompilationSettings.EnableUpaCheck = false;`after`XmlSchemaSet cache = new XmlSchemaSet();`but I'm still getting an XmlSchemaValidationException thrown with the message: "Wildcard '##any' allows element 'http://ibboard.co.uk/warfoundry/race:unitAbilities', and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate....[snip]"
IBBoard
<It doesn't seem to be working at the moment> You might try asking around at http://social.msdn.microsoft.com/Forums/en-US/xmlandnetfx/threads. I've had good luck getting information about intricate .NET XML issues there in the past, including from MSFT employees.
binarycoder
I've solved it now - it does work, but if you create an XmlSchemaSet and then Add() that to a XmlReaderSettings's Schemas then you need to set XmlReaderSettings.Schemas.CompilationSettings.EnableUpaCheck. Thanks for pointing me to the setting - this way makes far more sense to me.
IBBoard