c# - C# 中的 XML 模式 1.1 断言

标签 c# xsd

我正在使用以下 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: The http://www.w3.org/2001/XMLSchema:assert-element is not supported in this context.

我现在不知道的是是否...

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

提前感谢您的帮助!

最佳答案

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

关于c# - C# 中的 XML 模式 1.1 断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18331144/

相关文章:

c# - 90 度图像旋转和重置 EXIF 旋转

xsd - 为什么有些模式使用 <xsd :choice> instead of <xsd:enumeration>?

java - 如何提高 Java 中针对 xsd 的大型 xml 验证速度?

c# - 何时使用 ObservableCollection 与 AdvisableCollection 和 PostSharp NotifyPropertyChanged?

c# - 如何在 MongoDB C# Driver 2.0 中记录我的查询?

xsd - Spring Integration http 出站网关

XML::Compile 以使用枚举和选择从模式生成示例 XML

xml - XSD 错误 : Character content is not allowed, 因为内容类型为空

c# - 为什么这些异步 RIA 服务调用在 Web 服务器上串行执行?

c# - 如何安装 Moq 框架