About usage of maxOccurs

S

Sebastian Stein

Hi,

I have the following XSD file (XML Schema 1.0):

<xs:element maxOccurs="1" minOccurs="1" name="header">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:positiveInteger"/>
<xs:element name="name" type="xs:string"/>
<xs:element name="parentId" type="xs:positiveInteger"/>
<xs:element name="parentName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>

As the name says this should be the header for some kind of element. As it is a
header, it should only occur in the XML document ones. Therefore I added the
minOccurs and maxOccurs attributes. However, the xsv online validation check
(http://www.w3.org/2001/03/webdata/xsv) says:

Invalid per cvc-complex-type.1.3: undeclared attribute {None}:maxOccurs
Invalid per cvc-complex-type.1.3: undeclared attribute {None}:minOccurs

So I guess I'm not allowed to use those attributes at this point. How should I
proceed to fix this but also to note that this element is only allowed to occur
exactly one time in the XML document?!


Sebastian
 
M

Martin Honnen

Sebastian Stein wrote:

So I guess I'm not allowed to use those attributes at this point. How should I
proceed to fix this but also to note that this element is only allowed to occur
exactly one time in the XML document?!

Put that element definition in the right context e.g. of a sequence of
the root element (just an example)
<xsl:element name="root">
<xsl:complexType>
<xs:sequence>
<xs:element name="header">
The defaults for min/maxOccurs are 1 so there is no need to specify that
explictly.

You can also define that element standalone as a top level element as
you seem to have but then you need to specify minOccurs/maxOccurs where
you reference the element e.g.
<xsl:element name="root">
<xsl:complexType>
<xs:sequence>
<xs:element ref="header">
again you only need to specify min/maxOccurs if they are supposed to be
different from 1.

Also note that a top level element definition means any XML instance
document checked against the schema can have such an element as the root
element. That is usually not what you want.
 
S

Stan Kitsis [MSFT]

Hi Sebastian,

It looks like you define "header" as a global element. If this is the case,
it can only occur once in your instance document. Because of this,
minOccurs/maxOccurs attributes are not allowed on the global elements.

If this is not a global element, it needs to be inside a
sequence/choice/all.

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
S

Sebastian Stein

Stan Kitsis said:
It looks like you define "header" as a global element. If this is the case,
it can only occur once in your instance document. Because of this,
minOccurs/maxOccurs attributes are not allowed on the global elements.

If this is not a global element, it needs to be inside a
sequence/choice/all.

Yes, you both are correct. I forgot to put a root element around my document.

Thanks for spotting this!

Sebastian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top