Re: Global Vs Root Element.

[I missed the first part of this thread, so appologies for any repeated
information]
[actually terminology discussion is in the second part of this email]

Global Elements
---------------
Global elements refer to elements defined as the immediate children of the
<schema> element in an XSDL document (a schema definition document).  These
have three purposes:

1) to define elements which can be used be reference (i.e. <element
ref="some_global_element" />) _within_ other element, group, or type
definitons; and,
2) to define elements which can be legal document elements in instance
documents; and,
3) to define elements which can be used in instance documents where the
document's schema specifies <any> element may exist.

If you wish to define an element to be used only for <element ref="..."/>
purposes, the exact same semantics can be achieved by dropping this element in
a <group> element (I cannot take credit for this -- it was suggested to me on
this list some months ago).  The following pseudo XML/XSDL gives the general
idea:

Instance:
  <globalEle>
    <refEle>
  </globalEle>

Schema Before:
  <element name="refEle" type="myType" />
  <element name="globalEle" >
    <element ref="refEle" />
  </element>

After:
  <group name="refEle">
    <element name="refEle" type="myType" />
  </group>
  <element name="globalEle" >
    <group ref="refEle" />
  </element>

With the first schema, the following document would be schema valid:

<refEle />

But this would not be legal with the second schema.  The only issue then to
decide on is the naming convention for the group.  There is no name collision
since groups are in a different space from global element names, so this gives
the "appearance" of an element ref to "refEle".  I am still undecided about
how "nice" it is to do this (have groups and elements with the same name).  It
may not be unreasonable if restricted to _only_ these circumstances.  

Document Element (aka Root Element)
----------------
While "root element" is taken to be synonymous with "document element" it is
certainly my position that "document element" should be used in preference. 
There is also a "document root" which, not very helpfully, _could_ be confused
with either the term "root element" or "document element".  Example:

**** doc1.xml
<?xml version="1.0" ?>
<?some-pi execute="instruction" ?>
<!-- a small document -->
<doc>
  <!-- content goes here -->
  <content />
</doc>
<!-- some trailing comments -->

**** doc2.xml
<another_doc>
  <content />
</another_doc>

The document elements in these two documents are "doc" and "another_doc". 
These elements each contain a "content" element.  In contrast, the document
root in the first document contains 5 things:
1. The XML declaration: <?xml version="1.0" ?>
2. A processing instruction: <?some-pi execute="instruction" ?>
3. The first comment: <!-- a small document -->
4. The document element: <doc>
5. The second comment: <!-- some trailing comments -->

While the second document's root only contains 1 thing:
1. <another_doc>

Thinking about this in X-Path terms, "/" is the "document root" while "/doc"
or "/another_doc" are the "document elements".  It is tempting to call "/" the
"root element", or at least to think of it that way (it is the root of the
document), therefore it is wise NOT to use "root element" to refer to "/doc"
or "/another_doc", but instead use "document element".

Finally, a single schema document for these two documents may look like (again
in pseudo-XSDL):

<schema>
  <element name="doc">
    <element ref="content" />
  </element>
  <element name="another_doc">
    <element ref="content" />
  </element>
  <element name="content">
    <!-- some content model -->
  </element>
</schema>

Of course, taking into account my first comment on controling the difference
between global elements for use as references and global elements for document
elements, "content" is probably never meant to be a document element,
therefore I would put it inside a group definition to restrict this.

Regards,

Ian Stokes-Rees

-- 
Ian Stokes-Rees                       DecisionSoft Ltd.
Telephone: +44-1865-203192            http://www.decisionsoft.com

Venkateswar Wunnava wrote:
> 
> That is a good suggestion Tom.
> 
>  But I suppose XMLSpy is doing more ingenuine check above and beyond what
> XMLSchema Spec., stipulates. I suppose XMLScema specificatoin should have
> given a way to specify one of the global elements as root element in the
> form of a constraint, (some thing, XMLSpy is trying to infer). I personally
> do not like to hang around more than one global elements within a Schema
> unless I cannot do away with it. Particularly, because I do not want my
> Parser to punt on me by validating an instance that has a particular global
> element as a root element while I really did not intend to make it one,
> which, can be solved by a mechanism to specify one of those global elements
> as root element. I do not understand why this piece is being left so loose
> in the spec., while all possible forms of neat mechanisms have been provided
> in XMLSchema specification. Is there any specific reason for doing that,
> which I am missing?
> 
> Best Regards,
> 
> Venkateswar.
> 
> ----- Original Message -----
> From: "Tom Wason" <wason@mindspring.com>
> To: "Jeff Rafter" <jeffrafter@definedweb.com>; "Venkateswar Wunnava"
> <wvsvenkat@worldnet.att.net>
> Cc: <xmlschema-dev@w3.org>
> Sent: Monday, June 11, 2001 1:53 PM
> Subject: RE: Global Vs Root Element.
> 
> > Jeff--
> >
> > I agree with you in concept, as a schema may be a fragment.  However (ah
> > yes, however...), a general rule to use is that:
> >
> >  The root element can directly or indirectly contain all of the other
> > elements in the schema (presuming this is a complete schema).
> >
> > Therefore, the only "true" root element in this schema is <paragraph>.
> > Indeed, if you create a new XML instance with XML Spy, it will
> automatically
> > create an XML instance in which the root is <paragraph>.
> >
> > If you wanted to make all of the elements potentially root elements, you
> > could add the <paragraph> element to the complexType's <choice> list.
> >
> > --Tom
> >
> > Thomas D. Wason
> > e-Learning & Meta-Data Consultant
> > +1 919.839.8187
> > wason@mindspring.com
> > http://www.twason.com
> > 1421 Park Drive
> > Raleigh, North Carolina 27605 USA
> >
> > < -----Original Message-----
> > < From: xmlschema-dev-request@w3.org
> > < [mailto:xmlschema-dev-request@w3.org]On Behalf Of Jeff Rafter
> > < Sent: Monday, June 11, 2001 12:42 PM
> > < To: Venkateswar Wunnava
> > < Cc: xmlschema-dev@w3.org
> > < Subject: Re: Global Vs Root Element.
> > <
> > <
> > <
> > < Typically when referring to root elements you are referring to the
> > < first/outer element within an XML document (aka XML instance).
> > < For example:
> > <
> > < <?xml version="1.0" encoding="UTF-8"?>
> > < <root>
> > <   <child/>
> > < </root>
> > <
> > < The element <root> is the root element.  Global elements are referring
> to
> > < the element definitions within a schema document that appear as direct
> > < children of the <schema> element.  Within the schema definition
> > < there can be
> > < many global elements:
> > <
> > < <xsd:schema xmlns="paragraph" targetNamespace="paragraph"
> > < xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
> > < elementFormDefault="qualified">
> > <   <xsd:element name="paragraph" type="paraType"/>
> > <   <xsd:element name="bold" type="paraType"/>
> > <   <xsd:element name="italic" type="paraType"/>
> > <   <xsd:element name="underlined" type="paraType"/>
> > < ...
> > < <xsd:schema>
> > <
> > < (Quoting Tom Wason's recent example).  In this sample the elements
> > < paragraph, bold, italic and underline are all global.  Any of these can
> be
> > < used in an XML document as the root (however there is still only one
> root
> > < element per XML document).
> > <
> > < So the following XML documents would all be okay:
> > <
> > < <?xml version="1.0" encoding="UTF-8"?>
> > < <paragraph xmlns='paragraph'>
> > <   This is some <bold>text</bold>
> > < </paragraph>
> > <
> > < <?xml version="1.0" encoding="UTF-8"?>
> > < <bold xmlns='paragraph'>
> > <   This is some text
> > < </bold>
> > <
> > < <?xml version="1.0" encoding="UTF-8"?>
> > < <italic xmlns='paragraph'>
> > <   This is some <bold>text</bold>
> > < </italic>
> > <
> > < In each of these documents a different global element was used as the
> root
> > < element in an XML instance.
> > <
> > < Hope this helps,
> > < Jeff Rafter
> > < Defined Systems
> > < http://www.defined.net
> > < XML Development and Developer Web Hosting
> > <
> > < ----- Original Message -----
> > < From: "Venkateswar Wunnava" <wvsvenkat@worldnet.att.net>
> > < To: <xmlschema-dev@w3.org>
> > < Sent: Sunday, June 10, 2001 11:44 AM
> > < Subject: Global Vs Root Element.
> > <
> > <
> > < Hi,
> > <
> > <  I am not too familiar with XML. Can some one tell me what is the
> > < difference
> > < between Global Elements and Root Elements. From what I understand from
> > < XMLSchema specification, we cannot impose any cardinality constraints on
> > < Global Elements. They can occur with multiple instances as top level
> > < elements. I am confused how they are different from Root Element,
> > < which can
> > < be only one element. Thanks in advance.
> > <
> > < Best Regards,
> > <
> > < Venkateswar.
> > <
> > <
> > <
> >

-- 
Ian Stokes-Rees                       DecisionSoft Ltd.
Telephone: +44-1865-203192            http://www.decisionsoft.com

Received on Thursday, 5 July 2001 07:29:56 UTC