在 C# 中,如何确定元素的 XSD 定义的 MaxLength

5

本文介绍了在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

C# 中的多播委托奇怪行为?
Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)...
2023-11-11 C#/.NET开发问题
6

参数计数与调用不匹配?
Parameter count mismatch with Invoke?(参数计数与调用不匹配?)...
2023-11-11 C#/.NET开发问题
26

如何将代表存储在列表中
How to store delegates in a List(如何将代表存储在列表中)...
2023-11-11 C#/.NET开发问题
6

代表如何工作(在后台)?
How delegates work (in the background)?(代表如何工作(在后台)?)...
2023-11-11 C#/.NET开发问题
5

没有 EndInvoke 的 C# 异步调用?
C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)...
2023-11-11 C#/.NET开发问题
2

Delegate.CreateDelegate() 和泛型:错误绑定到目标方法
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)...
2023-11-11 C#/.NET开发问题
14