• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSD doubt

 
Hari babu
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.
<xsd:element name="A" type="foo"/>
<xsd:complexType name="foo">
<xsd:sequence>
<xsd:element name="B" �/>
<xsd:element name="C" �/>
</xsd:sequence>
</xsd:complexType>
2.
<xsd:element ref="foo"/>
<xsd:element name="foo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="B" �/>
<xsd:element name="C" �/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

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
Hari
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hari,
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.

Regards,
Dan
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Rakesh.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic