Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Top_Level Definition

 
Himal Chuli
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Himal,
Can you please get a little more specific? What is the topic/context you came across this term?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayadev Pulaparty ,very nice explanation.i got many thing from ur reply.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic