問題描述
我正在使用帶有附加 XSD 的 XmlReader 進(jìn)行驗證.
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)???
我認(rèn)為myReader.SchemaInfo.SchemaElement.Constraints
"可能會給我這些信息,但該集合的計數(shù)"始終為零.
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.
這篇關(guān)于在 C# 中,如何確定元素的 XSD 定義的 MaxLength的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!