473,602 Members | 2,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About usage of maxOccurs

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:positi veInteger"/>
<xs:element name="name" type="xs:string "/>
<xs:element name="parentId" type="xs:positi veInteger"/>
<xs:element name="parentNam e" 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}:maxOccur s
Invalid per cvc-complex-type.1.3: undeclared attribute {None}:minOccur s

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
Aug 14 '06 #1
3 1735


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:complexTyp e>
<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:complexTyp e>
<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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 14 '06 #2
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

"Sebastian Stein" <se*******@gmx. dewrote in message
news:cc******** ****@ID-116864.user.uni-berlin.de...
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:positi veInteger"/>
<xs:element name="name" type="xs:string "/>
<xs:element name="parentId" type="xs:positi veInteger"/>
<xs:element name="parentNam e" 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}:maxOccur s
Invalid per cvc-complex-type.1.3: undeclared attribute {None}:minOccur s

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

Aug 14 '06 #3
Stan Kitsis [MSFT] <sk***@microsof t.comwrote:
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
Aug 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1603
by: GB | last post by:
If I define the following schema which allows either a tag element OR an tag and origin_system elements I get an error. Same thing happens when I use groups. Is this because tag is defined twice? My reading of the XML-Schema spec seems to suggest that the schema is valid & that Xerces is in error. I get the error with Java Xerces 2.3.0 but not with C++ Xerces 1.7.0. Can anyone explain?
0
1330
by: Kurt | last post by:
Hi, (sorry if I'm cross posting - not quite sure where to put) I am basically trying to force the user of my web service to only send a valid dataset that is based on a schema I have created. I have created a schema which references another schema (like a library of complex and simple types) that has a complex typed defined called 'Related files', but when I generate a typed dataset from the xsd and use the WriteXMLSchema method then...
0
1004
by: Robert Rae | last post by:
Does anyone know of a way to set minoccurs and maxoccurs from an attribute. An example would be: public string HelloWorld(DataInput dataInput) { return "Hello World"; } public class DataInput
3
1742
by: Amol | last post by:
Hi all, I have a case where I have a element that can appear under multiple elements e.g. <AppFunctions> <UseTemplate name="1"/> <MethodSet name="2"> <UseTemplate name="3" /> <MethodCall name="4" /> </MethodSet>
2
3123
by: mavis | last post by:
The usage of <xs:choice maxOccurs="unbounded"> When we want to define a set of elements that could be in any order and with any occurences (0-unbounded), we can use <xs:choice maxOccurs="unbounded"> But I alway think that is not a good schema definition for XML files, and it must influence the writing and reading performance of these set of elements if there are large amounts of sub-elements. We can imagine that the retrieval of any...
2
1664
by: hooomee | last post by:
Given: <xs:choice maxOccurs=5> <xs:element name="Foo" type="bar" /> <xs:element name="Foo1" type="bar" /> <xs:element name="Foo2" type="bar" /> </xs:choice> Is the choice made once and then the choosen element can occur 5 times, or is the choice made once for each occurance?
3
3190
by: jlauman | last post by:
I'm getting an error on line 6 of the code shown below. The error is: Value 'unbounded' is not allowed for attribute 'maxOccurs' I'd appreciate any help in resolving this. Thanks, Jack <-- SNIP -->
3
2430
by: foolproofplan | last post by:
Maybe I am looking to far into a simple problem, but I am having quite a hard time figuring this out: I am currently trying to create a schema to represent an Element which contains other Elements (some of which have a restriction on how many can occur). Here is an example of what I have done if that seems confusing: <xsd:element name="Object"> <xsd:complexType>
2
4282
by: =?Utf-8?B?QW5keSBD?= | last post by:
Hi, I'm trying to load some XML into a dataset with C# but I have an issue with the schema. I'm using exactly the same code to successfully load other XML. The only difference is in the XML I'm trying to load it has: xs:choice maxoccurs="unbounded" The error message I'm getting is: "The 'maxoccurs' attribute is not
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3900
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.