• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Top_Level Definition

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Himal,
Can you please get a little more specific? What is the topic/context you came across this term?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jayadev Pulaparty ,very nice explanation.i got many thing from ur reply.
Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic