我正在使用以下 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.
我现在不知道的是是否...
- 我在 xsd 中的错误位置使用了断言元素
- http://www.w3.org/2001/XMLSchema-Namespace不支持 XML 模式 1.1 版,因此不支持断言元素
- C# XmlSchemaSet 不知道如何处理断言元素
提前感谢您的帮助!
最佳答案
XSD 架构的 .NET 实现仅处理 1.0 版而不处理 1.1 版 - 因此它不支持 assert
。
关于c# - C# 中的 XML 模式 1.1 断言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18331144/