W3C home > Mailing lists > Public > www-xml-schema-comments@w3.org > October to December 2002

Re: Same Element Different Attributes

From: C. M. Sperberg-McQueen <cmsmcq@acm.org>
Date: Wed, 02 Oct 2002 20:27:19 -0600
Message-Id: <>
To: brian@creativengine.com
Cc: W3C XML Schema Comments list <www-xml-schema-comments@w3.org>

At 2002-10-02 13:08, brian@creativengine.com wrote:

>I am trying to write a schema for an application we developed. It sends
>xml "requests" to a server and receives xml "replies". Im new to schema
>and i am having trouble figuring out the best way to organize it...the
>problem is, each request is a separate
>xml file i.e.
><REQUEST TYPE="GETDOCUMENT" UNID="1234556664325345"/>
>      <DOCUMENT UNID="555555555"/>
>      <DOCUMENT UNID="555555556"/>
>Basically the root element is always "REQUEST" but the attributes change.

Is there a reason you cannot allow the root element to
have different names for different request types?  E.g.

   <GETVIEW UNID="..." VIEWNAME="..."/>
      <DOCUMENT UNID="..."/>

?  That would allow the schema to validate the selection of
attributes for each element in a simple and straightforward
way.  For my way of thinking, it also makes the application
easier to understand, but it's clear that different people
think differently about this.

If you really really need them all to be called REQUEST, you
could define an abstract complex type for all requests, derive
other types from it, with appropriate additions to the set of
attributes, or by setting optional attributes to have
maxOccurs of 0, and then use xsi:type to tell the processor
which kind of request you want.  The complex types you
derive from your abstract request type might be called
GETDOCUMENT, GETVIEW, GETSUBSET, and so on. Your examples then

<REQUEST xsi:type="GETDOCUMENT" UNID="1234556664325345"/>

<REQUEST xsi:type="GETVIEW" UNID="1234556664325345" VIEWNAME="ALL"/>

<REQUEST xsi:type="GETSUBSET" UNID="1234556664325345" VIEWNAME="ALL">
      <DOCUMENT UNID="555555555"/>
      <DOCUMENT UNID="555555556"/>


I hope this helps.

-C. M. Sperberg-McQueen
Received on Wednesday, 2 October 2002 22:28:36 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:08:59 UTC