XSD.exe does not apply minOccurs

I have a simple scheme where I declare both minOccurs and maxOccurs 1. When I run XSD.exe to generate a C # class and consume the class in code; the field is not applied as required. Is there any other extra step? or are classes created using XSD.exe not required fields?

any suggestions or insights will be helpful.

+6
c # xml-serialization
source share
3 answers

As an Xml / infer schema tool in visual studio, whenever I used XSD.exe, I decided to fix some of the generated code. XSD.exe does a good approximation, but it does not work fully.

The error minOccurs / maxOccurs' is documented in MSDN.

When generating source code from an XML Schema Document, Xsd.exe ignores the minOccurs attribute that applies to <select> <sequence>, <group>, <all>, and <any> elements.

For an Xsd.exe element, it ignores the minOccurs attribute if the maxOccurs attribute value is greater than 1 or unlimited. In this case, the tool creates an array type corresponding to the given XSD type. Xsd.exe uses the value of the maxOccurs attribute to determine whether to create a single instance or array.

For the Xsd.exe element, it also ignores the minOccurs attribute if it is applied to the schema data type that is converted to a reference type in the .NET Framework.

Only under the following conditions are true. Xsd.exe uses the value of the minOccurs attribute:

Element is involved.

The maxOccurs attribute defines a single instance.

The data type is converted to a value of type.

+7
source share

How would you use custom minocockers in your code? Any statements? I think you can only display an array with a non-element single instance (1: 1) (non-zero) (1: many) and their equivalents with a zero value (0; 1) and (0: many)

+1
source share

You are correct that XSD.EXE does not apply the requirements for occurrence. It is provided.

0
source share

All Articles