XML Schema - Choice usage

P

puffy

Hi, Everyone!

I'd need a little help. I understand this is not valid, but is there
an (easy) way to make it valid?

<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence> <!-- static -->
<xs:element name="type" type="xs:positiveInteger" fixed="28251"/>
<xs:element name="h_align" type="h_align_Type"/>
<xs:element name="v_align" type="v_align_Type"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence> <!-- check -->
<xs:element name="type" type="xs:positiveInteger" fixed="28252"/>
<xs:element name="is_checked" type="xs:boolean"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

Thank you very much!
Chris
 
U

usenet

Hi, Everyone!

I'd need a little help. I understand this is not valid, but is there
an (easy) way to make it valid?

<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence> <!-- static -->
<xs:element name="type" type="xs:positiveInteger" fixed="28251"/>
<xs:element name="h_align" type="h_align_Type"/>
<xs:element name="v_align" type="v_align_Type"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence> <!-- check -->
<xs:element name="type" type="xs:positiveInteger" fixed="28252"/>
<xs:element name="is_checked" type="xs:boolean"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

Thank you very much!
Chris

I don't think schema currently offers any great solutions to this.
One option might be to do something like:

<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence> <!-- static -->
<xs:element name="type28251"
type="empty"/>
<xs:element name="h_align"
type="h_align_Type"/>
<xs:element name="v_align"
type="v_align_Type"/>
<xs:element name="text"
type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence> <!-- check -->
<xs:element name="type28252"
type="empty"/>
<xs:element name="is_checked"
type="xs:boolean"/>
<xs:element name="text"
type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

<xs:complexType name="empty"/>

Even I don't think that's pretty though!

Another option might be to use xsi:type in some way, and define a
number of restrictions or extensions for the various types.

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================
 
B

Boris Kolpackov

Hi,

puffy said:
<xs:complexType name="control_Type">
<xs:sequence>
<xs:element name="id" type="id_Type"/>
<xs:element name="position" type="pos_Type"/>
<xs:element name="name" type="xs:string"/>
<xs:choice>
<xs:sequence> <!-- static -->
<xs:element name="type" type="xs:positiveInteger" fixed="28251"/>
<xs:element name="h_align" type="h_align_Type"/>
<xs:element name="v_align" type="v_align_Type"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<xs:sequence> <!-- check -->
<xs:element name="type" type="xs:positiveInteger" fixed="28252"/>
<xs:element name="is_checked" type="xs:boolean"/>
<xs:element name="text" type="MultiLangText_Type"/>
</xs:sequence>
<!-- other control types -->
</xs:choice>
</xs:sequence>
</xs:complexType>

You need to make the first element in the two sequences differ
so the schema processor can figure out which arm of the choice
it is parsing just by looking at the first element. So one way
would be to place the 'type' element at the end. Or make it an
attribute. I like the attribute option better since it has the
nice notion of storing "meta information" in attributes and
"data" in elements.


hth,
-boris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top