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"
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.
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.
http://www.w3schools.com/schema/schema_example.asp says that: "The default value for both maxOccurs and minOccurs is 1!"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With