File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes ref vs type in XML Schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "ref vs type in XML Schema" Watch "ref vs type in XML Schema" New topic
Author

ref vs type in XML Schema

Lilly Wiesie
Greenhorn

Joined: Jan 20, 2005
Posts: 26
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

Joined: Jun 03, 2000
Posts: 5040
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


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Lilly Wiesie
Greenhorn

Joined: Jan 20, 2005
Posts: 26
Thanks.

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

Lilly
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ref vs type in XML Schema
 
Similar Threads
newbie question: ref or complex type ?
targetNamespace,xmlns
XML Schema and WSDL
ejb-local-ref and ejb-ref
Diff between elemment type and ref attribute