• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsd:all element

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.

THE SCHEMA

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"
targetNamespace="http://www.ziese.com/" xmlns="http://www.ziese.com/">

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

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

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

<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"/>
</xs:all>
</xs:complexType>

</xs:schema>

THE XML

<?xml version="1.0" encoding="UTF-8"?>
<Car xmlns="http://www.ziese.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ziese.com/
D:\CurrentProjects\WebServicesCertification\Documents\CHAPTE~1\carSchema.xsd">
<engineType>14Valve</engineType>
<partsValues>
<engine>122</engine>
<wheels>33</wheels>
</partsValues>
</Car>


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.

Thanks

Steve
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Thanks
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
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!
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stephen,

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!



Regards,
Dan
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic