Sequence Tag

Discussion in 'XML' started by Jason Cavett, Dec 6, 2007.

  1. Jason Cavett

    Jason Cavett Guest

    I'm curious about the sequence tag in XML. From my reading, the
    sequence tag requires that the elements "must appear in the same order
    as they are declared."

    I personally don't care about the order of the elements in the XML
    document (in fact, the elements could appear in any order within the
    complex type) - they just have to be there. Can I use something
    different other than sequence? I can't seem to find anything that
    lets me do this.


    Thanks
     
    Jason Cavett, Dec 6, 2007
    #1
    1. Advertising

  2. Jason Cavett

    geoff Guest

    Use 'all', they all have to appear but in any order.

    <xs:element name="letter">
    <xs:complexType mixed="true">
    <xs:all>
    <xs:element name="greeting"/>
    <xs:element name="body"/>
    <xs:element name="closing"/>
    </xs:all>
    </xs:complexType>
    </xs:element>

    --g
     
    geoff, Dec 6, 2007
    #2
    1. Advertising

  3. Jason Cavett

    Jason Cavett Guest

    On Dec 6, 11:37 am, "geoff" <> wrote:
    > Use 'all', they all have to appear but in any order.
    >
    > <xs:element name="letter">
    > <xs:complexType mixed="true">
    > <xs:all>
    > <xs:element name="greeting"/>
    > <xs:element name="body"/>
    > <xs:element name="closing"/>
    > </xs:all>
    > </xs:complexType>
    > </xs:element>
    >
    > --g


    Okay. What if I want any of them to appear? For example, <xs:all>
    means they all have to appear, but in any order, then what tag means
    that they can appear in any order, but I don't REQUIRE any of them?
    <xs:choice> seems to be right, but I just wanted to verify.

    Thanks
     
    Jason Cavett, Dec 10, 2007
    #3
  4. Jason Cavett wrote:

    > Okay. What if I want any of them to appear? For example, <xs:all>
    > means they all have to appear, but in any order, then what tag means
    > that they can appear in any order, but I don't REQUIRE any of them?
    > <xs:choice> seems to be right, but I just wanted to verify.


    With xs:choice you can specify
    <xs:choice minOccurs="0">
    so that the whole choice does not need to appear at all.
    The same goes for xs:sequence.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 10, 2007
    #4
  5. Jason Cavett

    Jason Cavett Guest

    On Dec 10, 11:00 am, Martin Honnen <> wrote:
    > Jason Cavett wrote:
    > > Okay. What if I want any of them to appear? For example, <xs:all>
    > > means they all have to appear, but in any order, then what tag means
    > > that they can appear in any order, but I don't REQUIRE any of them?
    > > <xs:choice> seems to be right, but I just wanted to verify.

    >
    > With xs:choice you can specify
    > <xs:choice minOccurs="0">
    > so that the whole choice does not need to appear at all.
    > The same goes for xs:sequence.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    Ah, okay. xs:sequence forces the order, though...that makes sense.
    Thank you.

    Is it possible to require that at least one of the elements appear
    (and as long as at least one of the elements appear, the others don't
    have to, but they can?).

    Also, I'm more than willing to read about this rather than coming back
    with all these questions. I just can't seem to find a good, concise
    website that explains the types of things I'm wondering about. I've
    been looking through the spec on w3, but it gets into far more detail
    than I need.
     
    Jason Cavett, Dec 10, 2007
    #5
  6. Jason Cavett wrote:

    > Is it possible to require that at least one of the elements appear
    > (and as long as at least one of the elements appear, the others don't
    > have to, but they can?).


    <xs:choice minOccurs="1" maxOccurs="unbounded">
    <xs:element name="el1" .../>
    <xs:element name="el2" .../>
    <xs:element name="el3" .../>
    </xs:choice>
    requires at least one of el1, el2, el3 and allows more of them.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 10, 2007
    #6
  7. Jason Cavett wrote:
    > Is it possible to require that at least one of the elements appear


    Set minOccurs on the choice to 1.

    (What you *can't* easily express in XML Schema would be a requirement
    that only one instance of any of the choices occurs. To get that, you
    wind up having to spell out most of the permutations explicitly. Most
    common solution is to implement that constraint in the application code
    or in a preprocessing stage such as a stylesheet; next most common
    (because less portable) is to switch to an alternative schema language.
    See past notes posted here for discussion.)

    > been looking through the spec on w3, but it gets into far more detail
    > than I need.


    My standard pointer: There are a lot of tutorials and articles on
    http://www.ibm.com/xml. (I'm sure there are other good websites too;
    that just happens to be the one I hit most often other than the W3C's
    own documents.)




    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Dec 10, 2007
    #7
  8. Jason Cavett

    Jason Cavett Guest

    On Dec 10, 1:27 pm, Martin Honnen <> wrote:
    > Jason Cavett wrote:
    > > Is it possible to require that at least one of the elements appear
    > > (and as long as at least one of the elements appear, the others don't
    > > have to, but they can?).

    >
    > <xs:choice minOccurs="1" maxOccurs="unbounded">
    > <xs:element name="el1" .../>
    > <xs:element name="el2" .../>
    > <xs:element name="el3" .../>
    > </xs:choice>
    > requires at least one of el1, el2, el3 and allows more of them.
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/


    Hrm...I guess I misunderstood choice.

    <xs:choice minOccurs="1" maxOccurs="unbounded">
    <xs:element name="el1" minOccurs="1" maxOccurs="1" />
    <xs:element name="el2" />
    <xs:element name="el3" />
    </xs:choice>

    In this case, I was thinking that the min/max on choice applied to
    each element individually (AKA I could have 1 - unbounded el1, 1 to
    unbounded el2, 1 to unbounded el3). However, by using min/max in el1,
    el1 CAN ONLY HAVE 1 occurrence but can have no more than 1 occurrence.

    So, I had already figured out the solution to my first problem...I
    just didn't realize it. So...how would I limit different elements to
    difference amounts of occurrences?


    Thanks again for your help.
     
    Jason Cavett, Dec 10, 2007
    #8
  9. > So, I had already figured out the solution to my first problem...I
    > just didn't realize it. So...how would I limit different elements to
    > difference amounts of occurrences?


    Simplest solution: Go back to requiring that they occur in a specific
    order, and set minOccurs/maxOccurs on each of them individually.

    Otherwise... See my other response regarding trying to set quantity
    limits without enforcing order. Basically, schema really isn't set up to
    do that.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Dec 10, 2007
    #9
    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. Luis Ferrao
    Replies:
    0
    Views:
    358
    Luis Ferrao
    Jan 3, 2005
  2. jstack
    Replies:
    1
    Views:
    646
    Tor Iver Wilhelmsen
    Jul 4, 2003
  3. kishan bisht

    struts tag inside a tag

    kishan bisht, Jul 8, 2003, in forum: Java
    Replies:
    1
    Views:
    1,513
    Wendy S
    Jul 9, 2003
  4. shruds
    Replies:
    1
    Views:
    933
    John C. Bollinger
    Jan 27, 2006
  5. stef mientki
    Replies:
    13
    Views:
    690
    stef mientki
    Oct 20, 2007
Loading...

Share This Page