Re: [schema] Re: Forcing a certain document element

Robert Braddock wrote:
> 
> > > Can't you design your schema to have only one global element definition
> 
> > In the words of Richard Nixon (allegedly :-) "You could do that, but
> > it would be wrong."  By which I mean you're right, if you wrote such a
> > schema, it would have the desired effect, but that's a pretty
> > roundabout way to get it.
> 
> I disagree. Given that the only way to avoid polluting my instance documents
> with redundant schema information is to insure that all elements are locally
> defined (except the top element, of course), it's hardly roundabout. In
> fact, since combining other schemas with mine relies on linking into them
> without violating this property, I appreciate if people design without
> global elements (I just use global complexTypes where I had global elements
> before).

That's quite a constraint, though, especially where multiple namespaces
are involved since types behave differently than elements in this
context.

Thinking more about it, there is another workaround which is to isolate
the elements within groups:

<schema>
  <element name="documentElement">
    <complexType>
      <group ref="someRefGroup" minOccurs="0" maxOccurs="unbounded"/>
    </complexType>
  </element>

  <group name="someRefGroup">
   <sequence>
    <element name="someRefElement">
     <complexType>
       <attribute name="foo" use="required"/>
       <attribute name="bar" use="required"/>
     </complexType>
    </element>
   </sequence>
  </group>
</schema>

should also do the trick.

If I can end this mail by a comment/question, I have always be surprised
that it's not allowed to define elements at any level, since the right
way to specify what is requested here could be something like:

<schema>
  <element name="documentElement">
    <!-- definition of an element available under 
         this scope   -->
    <element name="someRefElement">
     <complexType>
       <attribute name="foo" use="required"/>
       <attribute name="bar" use="required"/>
     </complexType>
    </element>
    <!-- Definition of the content modelm of 
         "documentElement" -->
    <complexType>
      <element ref="someRefElement" minOccurs="0"
maxOccurs="unbounded"/>
    </complexType>
  </element>
</schema>

But this is forbidden by the W3C XML Schema syntax.

Eric

> Robert Braddock

-- 
------------------------------------------------------------------------
Eric van der Vlist       Dyomedea                    http://dyomedea.com
http://xmlfr.org         http://4xt.org              http://ducotede.com
------------------------------------------------------------------------

Received on Friday, 12 January 2001 15:31:01 UTC