McMannus
McMannus

Reputation: 279

XML schema 1.1 assertions in C#

I'm validating some xml files with the following xml schema:

        String xsdMarkup = 
          "[...]

           <xsd:complexType name='connectionType'>
                <xsd:attribute name='SourceElement' type='guidType' use='required' />
                <xsd:attribute name='TargetElement' type='guidType' use='required' />
                <xsd:attribute name='GUID' type='guidType' use='required' />
                <xsd:assert test='@SourceElement == 0' />
           </xsd:complexType>

           [...]
          ";

        XmlSchemaSet schemas = new XmlSchemaSet();
        schemas.Add("", XmlReader.Create(new StringReader(xsdMarkup)));
        Console.WriteLine("Validating doc ...");
        docToValidate.Validate(schemas, (sender, e) =>
        {
            Console.WriteLine(e.Message);
            valid = false;
        }, true);

I just wanted to introduce some assert tags in order to have more powerful validation. But this leads to the exception:

System.Xml.Schema.XmlSchemaException: The http://www.w3.org/2001/XMLSchema:assert-element is not supported in this context.

What I don't know right now is whether...

  1. I used the assert-element in the wrong place inside the xsd
  2. The http://www.w3.org/2001/XMLSchema-Namespace doesn't support version 1.1 of XML Schema and thereby assert-elements
  3. C# XmlSchemaSet doesn't know how to deal with assert elements

Thanks for help in advance!

Upvotes: 6

Views: 3887

Answers (1)

MiMo
MiMo

Reputation: 11953

The .NET implementation of XSD schemas handle only version 1.0 and not version 1.1 - hence it does not support assert.

Upvotes: 8

Related Questions