Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Schema - Choice usage

Reply
Thread Tools

XML Schema - Choice usage

 
 
puffy
Guest
Posts: n/a
 
      04-05-2007
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="xsositiveInteger" 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="xsositiveInteger" 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

 
Reply With Quote
 
 
 
 
usenet@tech-know-ware.com
Guest
Posts: n/a
 
      04-05-2007
On 5 Apr, 08:49, "puffy" <(E-Mail Removed)> wrote:
> 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="xsositiveInteger" 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="xsositiveInteger" 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/
=============================================

 
Reply With Quote
 
 
 
 
Boris Kolpackov
Guest
Posts: n/a
 
      04-05-2007
Hi,

"puffy" <(E-Mail Removed)> writes:

> <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="xsositiveInteger" 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="xsositiveInteger" 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


--
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
web.xml / XML schema issue, why do some XML schema attributes disappear asciz@starmail.com Java 3 02-20-2007 09:56 AM
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML Schema to XML Schema Conversion Hari Om XML 1 03-02-2004 09:04 PM
XML schema regular expressions question and recommended XML Schema book Fred Smith XML 1 02-05-2004 11:12 AM



Advertisments