Re: XML Schemas patterns (was: Re: Defining recursive elements?)

Pete Cordell writes:

> I often see things like:
> 
>   <element name="thing">
>     <sequence>
>         <element name="height" type="measurementType"/>
>         <element name="width" type="measurementType"/>
>     </sequence>
>   </element>
> 
> <complexType name="measurementType">
>     <simpleContent>
>         <extension base="float">
>             <attribute name="units" type="string"/>
>         </extension>...
> 
> To me, this results in a lot of duplication if everything is to be made 
> global.

Let's see:

  <element name="thing">
    <sequence>
        <element ref="height"/>
        <element ref="width"/>
    </sequence>
  </element>

  <element name="height" type="measurementType"/>
  <element name="width" type="measurementType"/>
  <complexType name="measurementType">
    <simpleContent>
        <extension base="float">
            <attribute name="units" type="string"/>
        </extension>...

I don't see a whole lot of duplication.  Like the type, the elements are 
declared in one place and used in another.  Of course, there would be more 
payoff on that if it turned out that widths or heights were also needed 
outside of "things".

> I think it would also be harder to read as you would see the 
> local ref to height and then have to find the global definition
> (which could be a long way away) to find out what it's type is.

Yes.  I acknowledged that the syntax of Schema 1.0 facilitates the use of 
locals vs. globals, and suggested that to be unfortunate.  I would have 
seriously considered having the syntax of your original be interpreted to 
define a global, I.e. to do some sort of folding so that what were 
syntactically duplicate (for some definition of duplicate) element 
declarations would be folded into a single global, with differences 
allowed only if some other syntax or "local" switch were thrown.  As it 
stands, the local syntax is indeed more convenient, as I said in my note.

For the reasons Michael Kay's been giving, plus the one's I've been 
contributing, I think that the >semantics< of globals are usually 
preferable, and I don't think you've given any examples to indicate to the 
contrary.

--------------------------------------
Noah Mendelsohn 
IBM Corporation
One Rogers Street
Cambridge, MA 02142
1-617-693-4036
--------------------------------------

Received on Thursday, 17 May 2007 23:07:00 UTC