JL.
JL.

Reputation: 81262

XSD maxOccurs="unbounded"

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"

Upvotes: 11

Views: 66012

Answers (3)

Nick Bastin
Nick Bastin

Reputation: 31299

Yes. 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.

Upvotes: 16

Erik Svensson
Erik Svensson

Reputation: 59

http://www.w3schools.com/schema/schema_example.asp says that: "The default value for both maxOccurs and minOccurs is 1!"

Upvotes: 4

Welbog
Welbog

Reputation: 60398

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.

Upvotes: 4

Related Questions