XML架构1.1断言在C# [英] XML schema 1.1 assertions in C#
本文介绍了XML架构1.1断言在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下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 = '/>
< xsd:assert test ='@ SourceElement == 0'/>
< / xsd:complexType>
[...] b $ b;
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;
}真正);
我只是想介绍一些assert标签,以便有更强大的验证。但这会导致异常:
System.Xml.Schema.XmlSchemaException: http://www.w3.org/2001/XMLSchema:assert-element 在此上下文中不受支持。
我现在不知道是否...
- 我在xsd中的错误位置使用了assert-element
- http://www.w3.org/2001/XMLSchema-Namespace 不支持版本1.1的XML模式,从而断言元素
- C# XmlSchemaSet不知道如何处理断言元素 。
感谢您的帮助!
assert 。
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...
- I used the assert-element in the wrong place inside the xsd
- The http://www.w3.org/2001/XMLSchema-Namespace doesn't support version 1.1 of XML Schema and thereby assert-elements
- C# XmlSchemaSet doesn't know how to deal with assert elements
Thanks for help in advance!
解决方案
The .NET implementation of XSD schemas handle only version 1.0 and not version 1.1 - hence it does not support assert
.
这篇关于XML架构1.1断言在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文