File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "xsd:all element" Watch "xsd:all element" New topic
Author

xsd:all element

Stephen Baron
Greenhorn

Joined: Sep 16, 2010
Posts: 2
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
Mark Heron
Greenhorn

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.

Thanks
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
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!


My free books and tutorials: http://www.slideshare.net/krizsan
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1167
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

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
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