在C#中,如何确定XSD定义的最大长度为元素 [英] In C#, how to determine the XSD-defined MaxLength for an element
问题描述
我使用与验证的连接XSD的XmlReader。
I'm using XmlReader with an attached XSD for validation.
由于我的XML文档读取和验证,我要确定我的C#代码在XSD为特定元素指定最大长度的值。例如,我的XSD片段非常简单的定义为:
As my XML document is being read and validated, I want to determine in my C# code the 'maxLength' value specified in the XSD for a particular element. For example, my XSD fragment is very simply defined as:
<xsd:element name="testing" minOccurs="0">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
我可以很容易地得到'的minOccurs'值使用:
I can get the 'minOccurs' value easily using:
myReader.SchemaInfo.SchemaElement.MinOccurs;
但我怎么(在我的例子片段以上10值)获得了最大长度的价值? ??
But how do I get the 'maxLength' value (value of 10 in my example fragment above)???
我想' myReader.SchemaInfo.SchemaElement.Constraints
'可能给我这个信息,但该集合总有一个零计数。
I thought 'myReader.SchemaInfo.SchemaElement.Constraints
' might give me this information, but that collection always has a 'Count' of zero.
谢谢,
专利
推荐答案
你会发现在这里:的 访问XML Schema的信息在文档验证
如何做到这一点和放一个很好的解释;更多。
you'll find here:Accessing XML Schema Information During Document Validation
a good explanation of how to do this & more.
这篇关于在C#中,如何确定XSD定义的最大长度为元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!