tags:

views:

692

answers:

2

I have generated an XSD file from an XML snippet using xsd.exe /out

What its done is created maxOccurs="unbounded" properties for certain elements.

If I only want the element to appear once, and not be a collection do I set the maxOccurs like this?

maxOccurs="1"

Thanks

+1  A: 

Yes, that's how it's done.

maxOccurs limits the maximum number of repetitions of a given element that can appear.

Similarly, minOccurs limits the minimum number of repetitions.

They're called occurrence indicators. You can read more about them at W3Schools.

Welbog
So this means that if I set maxOccurs="1", when I generate the C# class, these properties wont become collections?
JL
I'm not sure about that one, but probably. If you want to know that you should include it in your question.
Welbog
+2  A: 

Yes. maxOccurs="unbounded" is actually the default, so you don't need it, but apparently xsd.exe feels like being thorough. Of course, keep in mind that maxOccurs is really maximum occurances - there can still be zero. If you want there to always be one, you'll need minOccurs="1" as well.

Nick Bastin