Newbie question, schema, complex types and unordered multiple elemets

Discussion in 'XML' started by davidjones@myself.com, Oct 16, 2007.

  1. Guest

    I want to model a situation where you can have multiple children of an
    element, and the children can be different types and in any order. A
    simple example of what I mean is at [1]. I am trying to make a schema
    to define this document, my attempted schema at [2].

    If I understand the format correctly I need to make the parent element
    (building) a complex type, and this must have an order indicator to
    contain other elements. None of the 3 order indicators (All, Choice,
    Sequence) fit my model.

    How do I do this? It seems I am missing something fundamental, or I
    am trying to model data that cannot be fit to xml.

    Thank you for any help.

    [1]
    <building name="house1">
    <window state="open"/>
    <door state="open"/>
    <door state="closed"/>
    <window state="closed"/>
    </building>

    [2]
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="building">
    <xs:annotation>
    <xs:documentation>a building</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence> <!-- This tag is the problem -->
    <xs:element name="window" maxOccurs="unbounded">
    <xs:complexType>
    <xs:attribute name="state" type="xs:string" use="required"/
    >

    </xs:complexType>
    </xs:element>
    <xs:element name="door" maxOccurs="unbounded">
    <xs:complexType>
    <xs:attribute name="state" type="xs:string" use="required"/
    >

    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
     
    , Oct 16, 2007
    #1
    1. Advertising

  2. Guest

    On 16 Oct, 14:45, wrote:
    > I want to model a situation where you can have multiple children of an
    > element, and the children can be different types and in any order. A
    > simple example of what I mean is at [1]. I am trying to make a schema
    > to define this document, my attempted schema at [2].
    >
    > If I understand the format correctly I need to make the parent element
    > (building) a complex type, and this must have an order indicator to
    > contain other elements. None of the 3 order indicators (All, Choice,
    > Sequence) fit my model.
    >
    > How do I do this? It seems I am missing something fundamental, or I
    > am trying to model data that cannot be fit to xml.
    >
    > Thank you for any help.
    >
    > [1]
    > <building name="house1">
    > <window state="open"/>
    > <door state="open"/>
    > <door state="closed"/>
    > <window state="closed"/>
    > </building>
    >
    > [2]
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > elementFormDefault="qualified" attributeFormDefault="unqualified">
    > <xs:element name="building">
    > <xs:annotation>
    > <xs:documentation>a building</xs:documentation>
    > </xs:annotation>
    > <xs:complexType>
    > <xs:sequence> <!-- This tag is the problem -->
    > <xs:element name="window" maxOccurs="unbounded">
    > <xs:complexType>
    > <xs:attribute name="state" type="xs:string" use="required"/
    >
    > </xs:complexType>
    > </xs:element>
    > <xs:element name="door" maxOccurs="unbounded">
    > <xs:complexType>
    > <xs:attribute name="state" type="xs:string" use="required"/
    >
    > </xs:complexType>
    > </xs:element>
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    > </xs:schema>


    One thing that might work for you is changing the xs:sequence in your
    schema to:

    <xs:choice maxOccurs="unbounded">...

    HTH,

    Pete.
    =============================================
    Pete Cordell
    Codalogic
    for XML Schema to C++ data binding visit
    http://www.codalogic.com/lmx/
    =============================================
     
    , Oct 16, 2007
    #2
    1. Advertising

  3. Guest

    On 16 Oct, 20:11, wrote:
    > One thing that might work for you is changing the xs:sequence in your
    > schema to:
    >
    > <xs:choice maxOccurs="unbounded">...


    Thanks, that does exactly what I want. It does not seems to do what
    w3schools says it does:

    from http://www.w3schools.com/schema/schema_complex_indicators.asp

    The <choice> indicator specifies that either one child element or
    another can occur:

    Is there a more accurate description of what these tags really mean?

    Thank you for the help.
     
    , Oct 17, 2007
    #3
  4. Re: Newbie question, schema, complex types and unordered multipleelemets

    > Thanks, that does exactly what I want. It does not seems to do what
    > w3schools says it does:


    Unfortunately, most of what I've heard about w3schools suggests that it
    isn't a particuarly well-organized resource (often not complete,
    sometimes not accurate).

    Choice says that any of the contained items can occur at this point. The
    default if those aren't specified is exactly one instance of the choice,
    no more and no less, but the standard Schema attributes such as
    maxOccurs can be used to change that.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Oct 17, 2007
    #4
    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. CJ
    Replies:
    0
    Views:
    756
  2. Naresh Agarwal
    Replies:
    1
    Views:
    1,291
    Martin Honnen
    Mar 7, 2004
  3. Kevin Campbell
    Replies:
    3
    Views:
    1,009
    Kevin Campbell
    Apr 26, 2004
  4. Stanimir Stamenkov
    Replies:
    2
    Views:
    763
    Stanimir Stamenkov
    Oct 25, 2005
  5. Replies:
    6
    Views:
    240
    janislaw
    May 17, 2007
Loading...

Share This Page