File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Product and Other Certifications and the fly likes XSD doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "XSD doubt" Watch "XSD doubt" New topic

XSD doubt

Hari babu
Ranch Hand

Joined: Jun 25, 2001
Posts: 208
<xsd:element name="A" type="foo"/>
<xsd:complexType name="foo">
<xsd:element name="B" �/>
<xsd:element name="C" �/>
<xsd:element ref="foo"/>
<xsd:element name="foo">
<xsd:element name="B" �/>
<xsd:element name="C" �/>

I have couple of questions
1. Is the 2nd XSD a correct definition ?
2. Whats the diffrence between the two definition. In first i have used "Type". In second it uses "reference"
Can anyone clear my doubts ?
Thanks in advance
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
My understanding is that you use types when types are involved.
Sometimes, on the other hand, you just want to break down your schema to more manageable pieces, without introducing new types.
In just a case you can use the reference way.
So, for example, the element toysco is very complex. The customer part is an element, which is referred to by element name in the toysco element. The same is done for the product and invoice elements.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Rakesh Gudur
Ranch Hand

Joined: Apr 29, 2002
Posts: 79
Hari babu,
The first one is a named complex type and the second one is an anonymous complex type. As the name suggests, a named complex type can be reused with the name.
In the case of an anonymous complex type, you have to include the complexType definition in an element and refer to the element as given in the second snippet.
In case of named complexType, you can directly refer to the complexType from an element as given in the first snippet.
It is important to note the way the complexType is referred to from the elements in both the cases.
For more details check out the Primer in w3c spec.
Thank you,
I agree. Here's the link:
subject: XSD doubt
It's not a secret anymore!