aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes xsd:all element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "xsd:all element" Watch "xsd:all element" New topic

xsd:all element

Stephen Baron

Joined: Sep 16, 2010
Posts: 2

Can someone please give me some pointers on how my understanding og xsd:all element. I was under the impression that this allowed element to exist in any order or if minOccurs="0" is stipulated, allow elements to be optional or in any order. However I cant get the following XML to verify against the schema.


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="" elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="" xmlns="">

<xs:element name="Car"> <!-- global element. Not wrapped by type -->
<xs:complexType> <!-- embedded type -->
<xs:element name="engineType" type="engineType"/>
<xs:element name="partsValues" type="partsValue"/>

<xs:complexType name="Engine">
<xs:element name="EngineType" type="engineType"/>

<xs:simpleType name="engineType">
<xs:restriction base="xs:string">
<xs:enumeration value="14Valve"/>
<xs:enumeration value="8Valve"/>
<xs:enumeration value="16Valve"/>

<xs:complexType name="partsValue">
<xs:all minOccurs="0"> <!-- child elements can exist in any order -->
<xs:element name="engine" type="xs:integer"/> <!-- and can optionally exist -->
<xs:element name="exhaust" type="xs:integer"/>
<xs:element name="wheels" type="xs:integer"/>



<?xml version="1.0" encoding="UTF-8"?>
<Car xmlns="" xmlns:xsi="" xsi:schemaLocation="

Its complaining as I havent included exhaust. If I remove the minOccurs it complains as the order isnt correct. Im using XML Spy for validation.

Any help would be greatly appreciated.


Mark Heron

Joined: Aug 19, 2010
Posts: 20

Hi Steve,

<all minOccurs="0"> means combination of all elements can occur minimum zero times. In other words minOccurs value applies to group element <all> not individual element within <all></all> group. So in your case if you remove lines <engine>122</engine> and <wheels>33</wheels> XML validation succeed. If you change minOccurs="1"(Default) and do not provide <partsValues> group or provide empty <partsValues /> then it will complain about all 3 elements.

Hope this will help.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
From my SCDJWS study notes:
Complex types can be declared containing the <all> element in the place of the <sequence> element. The <all> element cause the elements of the complex type to:
• Child elements of the complex type can appear in any order.
• Child elements always have a maxOccurs of 1 and a minOccurs of 0.
• Only single elements may occur in an <all> group.
No groupings like <sequence> or <all> can occur in an <all> group, however, custom types declared using either <simpleType> or <complexType> can occur in an <all> group.

I don't see why you want to include the minOccurs attribute on the <all> element - see above about minOccurs and maxOccurs of the child elements of the <all> element.
If you want the <partsValue> element to be optional, this is what you'd write in your schema:

If you use <all>, you cannot choose whether a child element of <all> is to be optional or not - they all are optional and can, at most, occur once.
Best wishes!

My free books and tutorials:
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1164

According to XML Schema all Element you are right. It says -

The example above indicates that the "firstname" and the "lastname" elements can appear in any order and each element CAN appear zero or one time!


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
I agree. Here's the link:
subject: xsd:all element
Similar Threads
XSD element validation
schema generation
XML valiadation using schema
Axis 1.4 throwing org.xml.sax.SAXException: Invalid element
unble to validate xml against schema