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


>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:element ref="texto"/>
  <xsd:attribute name="valor"/>

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

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:element name="consulta" type="consultaTipo" />
    <xsd:element name="recurso" type="recursoTipo" />

<!-- Then within your pantalla -->
<xsd:element name="pantalla">
      <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"
    <xsd:attribute name="nombre"/>

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