[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Problem w/ Schema for elements with similar defs

  • From: Jeff Rafter <jeffrafter@e...>
  • To: José Manuel Beas <jmbeas@t...>
  • Date: Tue, 02 Jan 2001 10:46:26 -0800

xsd choice between groups
José,

>5. "consulta" and "recurso" have some common characteristics:
>5.1. Both have an attribute called "valor"
>5.2. Both can content an element "texto"
>5.3. Only "consulta" can content an element "imagen"

One possible solution (recommended) is to utilize the extension features
built into XML Schemas:

<xsd:complexType name="recursoTipo">
  <xsd:sequence>
    <xsd:element ref="texto"/>
  </xsd:sequence>
  <xsd:attribute name="valor"/>
</xsd:complexType>

<!-- consulta extends recurso, because it adds the imagen element -->
<xsd:complexType name="consultaTipo">
  <xsd:complexContent>
    <xsd:extension base="recursoTipo">
      <xsd:sequence>
        <xsd:element ref="imagen"/>
      </xsd:sequence>
    </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

Now that you have your types declared as such you could easily answer the
question 4, assuming you didn't mind changing the names of the elements
"consulta" and "recurso" to something more neutral.  By simply using the
xsi:type attribute within your instance documents you could specify what
type of object (complexType) would be used [1].  Simply change the
declaration of pantalla to reflect the new model.

However, I will assume that this isn't the solution you are looking for and
demonstrate how to do it using an xsd:group/xsd:choice:

<!-- First declare a group that has a choice between consulta and
recurso -->
<xsd:group name="consultaAndResurso">
  <xsd:choice>
    <xsd:element name="consulta" type="consultaTipo" />
    <xsd:element name="recurso" type="recursoTipo" />
  </xsd:choice>
</xsd:group>

<!-- Then within your pantalla -->
<xsd:element name="pantalla">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element ref="parametros" minOccurs="0" maxOccurs="1"/>
      <xsd:element ref="dimensiones" minOccurs="1" maxOccurs="1"/>
      <!-- Then refer to the group and make it unbounded -->
      <xsd:group    ref="consultaAndRecurso" minOccurs="0"
maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="nombre"/>
  </xsd:complexType>
</xsd:element>

I think that this will work, but must admit I am not the resident expert in
this area.

[1] http://www.w3.org/TR/xmlschema-0/#UseDerivInInstDocs

Jeff Rafter
Defined Systems


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.