[standards-jig] sequence vs. choice

Peter Saint-Andre stpeter at jabber.org
Wed Feb 6 23:07:21 UTC 2002


As I'm working on the schemas for the RFC, I'm wondering how we want to
codify some of the XML. I think in the past we have not enforced sequence
in the elements that are included within a <message/>, <presence/>, or
<iq/> chunk, nor (necessarily) the number of allowable instances of child
elements. So for instance the following two chunks are both valid as far
as I can see:

<presence 
    from='maineboy66 at jabber.org/Gabber'
    to='stpeter at jabber.org'>
  <status>Automatically away due to being idle</status>
  <show>xa</show>
  <x xmlns='jabber:x:signed'>signedstatushere</x>
  <x xmlns='gabber:x:music:info'>
    <title>Awaken.mp3</title>
    <state>playing</state>
  </x>
</presence>

<presence
    from='maineboy66 at jabber.org/Gabber'
    to='stpeter at jabber.org'>
  <x xmlns='gabber:x:music:info'>
    <title>Awaken.mp3</title>
    <state>playing</state>
  </x>
  <status>Automatically away due to being idle</status>
  <x xmlns='jabber:x:signed'>signedstatushere</x>
  <show>xa</show>
</presence>

Do we want to enforce any given sequence of elements? Personally I would
prefer that. The resulting schema snippet would look something like this:

      <xsd:sequence>
        <xsd:element ref='status' minOccurs='0' maxOccurs='1'/>
        <xsd:element ref='priority' minOccurs='0' maxOccurs='1'/>
        <xsd:element ref='show' minOccurs='0' maxOccurs='1'/>
        <xsd:any namespace='##any' minOccurs='0' maxOccurs='unbounded'/>
        <xsd:element ref='error' minOccurs='0' maxOccurs='1'/>
      </xsd:sequence>

(since <error/> elements seem to go at the end in current implementations)

A similar snippet for <message/> would be:

      <xsd:sequence>
        <xsd:element ref='thread' minOccurs='0' maxOccurs='1'/>
        <xsd:element ref='subject' minOccurs='0' maxOccurs='1'/>
        <xsd:element ref='body' minOccurs='0' maxOccurs='1'/>
        <xsd:any namespace='##any' minOccurs='0' maxOccurs='unbounded'/>
        <xsd:element ref='error' minOccurs='0' maxOccurs='1'/>
      </xsd:sequence>

And for IQ:

     <xsd:sequence>
       <xsd:any namespace='##any' minOccurs='0' maxOccurs='unbounded'/>
       <xsd:element ref='error' minOccurs='0' maxOccurs='1'/>
     </xsd:sequence>

However, right now sequence is not enforced in any way, so this would mean
some current implementations would not comply with above snippets. (!)

We could also stick with no enforced sequences, as so:

     <xsd:choice minOccurs='0' maxOccurs='1'>
       <xsd:element ref='body' />
       <xsd:element ref='subject' />
       <xsd:element ref='thread' />
       <xsd:any namespace='##any' />
       <xsd:element ref='error' />
     </xsd:choice>

XML schemas question: can do the following to override the maxOccurs on
the <xsd:choice/> element?

     <xsd:choice minOccurs='0' maxOccurs='1'>
       <xsd:element ref='body' />
       <xsd:element ref='subject' />
       <xsd:element ref='thread' />
       <xsd:any namespace='##any' minOccurs='0' maxOccurs='unbounded' />
       <xsd:element ref='error' />
     </xsd:choice>

Let the flames begin.

Peter

--
Peter Saint-Andre
email+jabber: stpeter at jabber.org
web: http://www.saint-andre.com/




More information about the Standards mailing list