Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: schema design for one element, multiple types

From: George Cristian Bina <george@----.-->
To: "Kevin Y. Kim (Lists)" <kykim_lists@---.--->
Date: 11/9/2005 11:56:00 AM
Hi Kevin,

The best you can do is to make the element optional and the complex type 
mixed. That will give you a relaxed model that will cover both cases:

<xs:complexType name="foo2" mixed="true">
   <xs:sequence>
     <xs:element name="bar" type="xs:string" minOccurs="0"/>
   </xs:sequence>
</xs:complexType>

Additional constraints can be enforced then either at application level 
or embedding Schematron rules in your XML Schema.

There is also the option of using xsi:type to specify the type for foo 
in the instance document, see Michael Kay's answer two days ago on this 
list.
Then you will have something like:

<some_xml>
   <foo xsi:type="foo1">some_value</foo>
   <foo xsi:type="foo2">
     <bar>another_value</bar>
   </foo>
   <foo xsi:type="foo1">third_value</foo>
</some_xml>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
www.---.com


Kevin Y. Kim (Lists) wrote:
> 
> Hi,
> 
> I'm trying to define a schema that will support the following:
> 
> 1    <some_xml>
> 2        <foo>some_value</foo>
> 3        <foo>
> 4            <bar>another_value</bar>
> 5        <foo>
> 6        <foo>third_value</foo>
> 7    </some_xml>
> 
> Now, I know how to defined the schema for each case:
>     For 2 & 6:
>         <xsd:complexType name="foo1">
>             <xsd:simpleContent>
>                 <xsd:extension type="xsd:string"/>
>             </xsd:simpleContent>
>         </xsd:complexType>
> 
>     For 3 - 5:
>         <xsd:complexType name="foo2">
>             <xsd:sequence>
>                 <xsd:element name="bar" type="xsd:string"/>
>             </xsd:sequence>
>         </xsd:complexType>
> 
> But how would I defined a schema to encompass both?
> 
> Thanks,
> -kevin
> 
> 
> 

From etishkin@m... Wed Nov 09 14:52:03 2005
Received: from wiggum.w3.org ([128.30.52


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent