gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:58:38 24 4
gpt4 key购买 nike

我正在使用以下 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com