XML Schema - Choice usage

Discussion in 'XML' started by puffy, Apr 5, 2007.

  1. puffy

    puffy Guest

    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
     
    puffy, Apr 5, 2007
    #1
    1. Advertising

  2. puffy

    Guest

    On 5 Apr, 08:49, "puffy" <> 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="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/
    =============================================
     
    , Apr 5, 2007
    #2
    1. Advertising

  3. Hi,

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


    --
    Boris Kolpackov
    Code Synthesis Tools CC
    http://www.codesynthesis.com
    Open-Source, Cross-Platform C++ XML Data Binding
     
    Boris Kolpackov, Apr 5, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mickey Segal
    Replies:
    0
    Views:
    903
    Mickey Segal
    Feb 2, 2004
  2. Markus
    Replies:
    1
    Views:
    1,580
    Markus
    Nov 23, 2005
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,275
    Stanimir Stamenkov
    Apr 25, 2005
  4. Replies:
    3
    Views:
    2,895
  5. miles.jg
    Replies:
    16
    Views:
    889
    Alf P. Steinbach
    Nov 14, 2007
Loading...

Share This Page