W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2002

Re: Pls do the need full

From: Jeni Tennison <jeni@jenitennison.com>
Date: Fri, 19 Apr 2002 10:04:02 +0100
Message-ID: <1821474211754.20020419100402@jenitennison.com>
To: "Ibrahim Hunkunti" <ibrahim.hunkunti@wipro.com>
CC: xmlschema-dev@w3.org
Hi Ibrahim,

> I'm new to XML schema development so my question might be really
> very simple. I want to know how to find out an element is mandatory
> or optional from xml schema.

Whether or not an element is mandatory or optional within a particular
other element depends on the *content model* of that other element.
You'll see things like:

  <xs:sequence>
    <xs:element name="E1" />
    <xs:element ref="E2" minOccurs="0" />
    <xs:element name="E3" minOccurs="3" maxOccurs="unbounded" />
  </xs:sequence>

within a schema.

Whether a particular element is mandatory or optional depends on
whether it has a minOccurs attribute and what the value of that
minOccurs attribute is. The minOccurs attribute specifies the minimum
number of times that the element must occur. If it's one or more then
the element must occur. If it's zero, then the element is optional. If
the minOccurs attribute is missing, it's the same as specifying it
with the value 1.

So in the model group above, element E1 is mandatory (minOccurs is
missing, so it defaults to 1), element E2 is optional (minOccurs is 0)
and element E3 is mandatory (in fact must occur at least three times).

The maxOccurs attribute similarly indicates the maximum number of
times the element can occur, defaults to 1 if it's missing, and can
take the value 'unbounded' to mean "there's no maximum".

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Friday, 19 April 2002 05:04:04 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:30 GMT