aspose file tools*
The moose likes Product and Other Certifications and the fly likes Top_Level Definition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "Top_Level Definition" Watch "Top_Level Definition" New topic
Author

Top_Level Definition

Himal Chuli
Ranch Hand

Joined: Aug 06, 2002
Posts: 118
hi,
while going thru schema, i came across a term "top-level definition". could you please explain me what it is and it's significance? what does set it apart from others?
thanks.
himal


Himal
Jayadev Pulaparty
Ranch Hand

Joined: Mar 25, 2002
Posts: 662
Himal,
Can you please get a little more specific? What is the topic/context you came across this term?
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
Roger says in his slides -
Terminology: Global versus Local
----------------------------------------
Global element declarations, global type definitions:
These are element declarations/type definitions that are immediate children of <schema>
Local element declarations, local type definitions:
These are element declarations/type definitions that are nested within other elements/types.
Global vs Local … What's the Big Deal?
So what if an element or type is global or local. What practical impact does it have?
Answer: only global elements/types can be referenced (i.e., reused). Thus, if an element/type is local then it is effectively invisible to the rest of the schema (and to other schemas).

BTW, Roger's material on Schemas is outstanding! (http://www.XFront.com)
Thank you Vinayak for the link.
Cheers,
Dan
[ September 17, 2002: Message edited by: Dan Drillich ]
[ September 17, 2002: Message edited by: Dan Drillich ]

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

Joined: Mar 25, 2002
Posts: 662
I guess what Costello meant by re-use of the global elements in a schema is as follows �
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.test.org"
targetNamespace="http://www.test.org"
elementFormDefault="qualified">
<!�THIS ELEMENT WILL BE REUSED by globalElement2 �
<xsd:element name="globalElement1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="globalType">
<xsd:sequence>
<xsd:element name="localElement1" type="xsd:string"/>
<xsd:element name="localElement2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="globalElement3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement4" type="globalType"/>
<xsd:element name="localElement5" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="globalElement2">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="globalElement1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
If you look at globalElement2, it is referring to globalElement1. If you try replacing globalElement1 with localElement3, the schema validator will flag error as localElement3 is local to globalElement1. This is true for complexTypes also.
One more important thing for you to see here is that xmlns=http://www.test.org SHOULD be defined here as an attribute for <xsd:schema> element. Otherwise, we wouldn�t be referring to globalElement1 of http://www.test.org namespace from globalElement2 and the validator will give you an error about this.
Also, only global elements will be seen from the instance documents as shown below �
Schema file �
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.test.org"
elementFormDefault="qualified">
<xsd:element name="globalElement1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement3" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="globalType">
<xsd:sequence>
<xsd:element name="localElement1" type="xsd:string"/>
<xsd:element name="localElement2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="globalElement3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="localElement4" type="globalType"/>
<xsd:element name="localElement5" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="globalElement2">
<xsd:complexType>
<xsd:sequence>
<xsd:any/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
XML document �
<?xml version="1.0"?>
<globalElement2 xmlns="http://www.test.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.test.org
test.xsd">
<localElement3/>
</globalElement2>
If we try validating this xml file against the schema given above, we get an error about localElement3. This clearly shows that the instance document can only see the global elements in the schema. If you modify the stuff as shown below, it will be a valid instance document.
<?xml version="1.0"?>
<globalElement2 xmlns="http://www.test.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.test.org
test.xsd">
<globalElement1>
<localElement3/>
</globalElement1>
</globalElement2>
Ronak Patel
Ranch Hand

Joined: Aug 14, 2002
Posts: 31
Jayadev Pulaparty ,very nice explanation.i got many thing from ur reply.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Top_Level Definition