OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem w/ Schema for elements with similar defs



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