XML schema 1.1 assertions in C#

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

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!

回答1:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!