Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ref vs type in XML Schema

 
Lilly Wiesie
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would somebody tell me what's the difference between ref and type in XML schema. Seems we can use either of them. The difference seems subtle.

Thanks.

Lilly
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The type attribute is used to associate either a standard or user-defined simple type or a complex type in a declaration. Examples would be defining an attribute of type="string" or type="integer", something like that.

While the ref attribute is used in a declaration to associate another declaration of element/attribute which has a type. Its like declaring the type only indirectly. I would read this as 'I am of the same type as that other element'. Examples of the use of the ref attribute would be say a declaration of the Shipping-Address and Billing-Address elements. You declare the Shipping-Address element using the type attribute and associate it to a user-defined complex-type. Once that is done, you can declare the Billing-Address using the ref attribute and declare that the Billing-Address is the same type as the Shipping-Address element.

<!--
......
declare complex type AddressType.....
-->
<xsd:element name="Shipping-Address" type="AddressType"/>
<!--
......
other declarations
.....
-->
<xsd:element name="Billing-Address" ref="Shipping-Address"/>
<!--
......
other declarations
.....
-->

The ref attribute is mostly used to associate types from different namespaces.

- m
 
Lilly Wiesie
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

It looks confusing at the beginning. I got it now.

Lilly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic