In C #, how to define a definable XSD MaxLength for an element

I am using XmlReader with XSD attached for validation.

Since my XML document is read and validated, I want to define in my C # code the value "maxLength" specified in the XSD for a specific 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> 

I can easily get the minOccurs value using:

 myReader.SchemaInfo.SchemaElement.MinOccurs; 

But how do I get the value of maxLength (value 10 in my example above) ???

I thought that " myReader.SchemaInfo.SchemaElement.Constraints " could give me this information, but this collection always has a "graph" of zero.

Thanks,

Pat.

+3
c # maxlength xsd
source share
2 answers

You will find here: Accessing XML Schema Information During Document Validation good explanation of how to do this and more.

+5
source share

There are ways to do this with myReader.SchemaInfo (see najmeddine's answer), but if you need to access materials that don't appear in the SchemaInfo object ...

.. XSD is an XML language. You can simply download the XSD file and use XPath to find the definition of the test item and its maximum length.

+1
source share

All Articles