【问题标题】:XML schema 1.1 assertions in C#C# 中的 XML 模式 1.1 断言
【发布时间】:2013-08-20 09:08:30
【问题描述】:

我正在使用以下 xml 架构验证一些 xml 文件:

        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);

我只是想引入一些断言标签,以便进行更强大的验证。但这导致了异常:

System.Xml.Schema.XmlSchemaException:此上下文不支持http://www.w3.org/2001/XMLSchema:assert-element

我现在不知道是不是……

  1. 我在 xsd 中的错误位置使用了 assert-element
  2. http://www.w3.org/2001/XMLSchema-Namespace 不支持 1.1 版的 XML Schema,因此不支持断言元素
  3. C# XmlSchemaSet 不知道如何处理断言元素

提前感谢您的帮助!

【问题讨论】:

标签: c# xsd


【解决方案1】:

XSD 架构的 .NET 实现仅处理 1.0 版而不是 1.1 版 - 因此它不支持 assert

【讨论】:

  • 当然,总是有 Saxon ... 仅仅因为您使用 C# 并不意味着 MS 工具是您唯一的选择。
猜你喜欢
  • 1970-01-01
  • 2013-03-12
  • 2014-07-18
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多