In C#, how to determine the XSD-defined MaxLength for an element(在 C# 中,如何确定元素的 XSD 定义的 MaxLength)
问题描述
我正在使用带有附加 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C# 中,如何确定元素的 XSD 定义的 MaxLength


- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01