我正在使用带有附加 XSD 的 XmlReader 进行验证.
I'm using XmlReader with an attached XSD for validation.
在读取和验证我的 XML 文档时,我想在我的 C# 代码中确定 XSD 中为特定元素指定的maxLength"值.例如,我的 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;
但是我如何获得maxLength"值(在我上面的示例片段中的值为 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 模式信息 很好地解释了如何做到这一点 &更多.
you'll find here:Accessing XML Schema Information During Document Validation a good explanation of how to do this & more.
这篇关于在 C# 中,如何确定元素的 XSD 定义的 MaxLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
车牌检测有哪些好的算法?What are good algorithms for vehicle license plate detection?(车牌检测有哪些好的算法?)
Unity中图像的onClick事件onClick event for Image in Unity(Unity中图像的onClick事件)
运行总 C#Running Total C#(运行总 C#)
单击带有 JAvascript.ASP.NET C# 的超链接时删除目录Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(单击带有 JAvascript.ASP.NET C# 的超链接时删除目录)
asp.net listview 在单击时突出显示行asp.net listview highlight row on click(asp.net listview 在单击时突出显示行)
从函数调用按钮 OnClickCalling A Button OnClick from a function(从函数调用按钮 OnClick)