Re: [SOAP] xsd:choice maxOccurs=unbounded, and element order

[email protected] (Ammarmar)
Newsgroups php.soap
Message-ID <[email protected]>
Actually, depending on XML structure to preserve order is dangerous. As  
you can see, even if order in XML is OK, some part of processing (in this  
case PHP) can mess it up. Generally, it is understood that XML does NOT  
preserve order by itself.

To preserve order assign unique ID to each element. It is also (IMO) a  
good idea to use single 'word' element type instead of several types. E.g:

<xsd:complexType name='containertype'>
   <xsd:sequence maxOccurs='unbounded'>
     <xsd:element name='word' type='word'/>
   </xsd:choice>
</xsd:complexType>

<xsd:complexType name='word'>
   <xsd:element name='id' type='xsd:positiveInteger'/>
   <xsd:element name='type'>
     <xsd:simpleContent>
       <xsd:restriction base='xsd:string'>
         <xsd:enumeration value='noun'/>
         <xsd:enumeration value='verb'/>
         ....
        </xsd:restriction>
     </xsd:simpleContent>
   </xsd:element>
   <xsd:element name='value' type='xsd:string'/>
</xsd:complexType>


This describes such XML:

<container>
   <word>
     <id>1</id>
     <type>noun</type>
     <value>John</value>
   </word>
   <word>
     <id>2</id>
     <type>verb</type>
     <value>has</value>
   </word>
   <word>
     <id>3</id>
     <type>noun</type>
     <value>kittens</value>
   </word>
</container>

Creating and iterating on such structure in PHP shouldn't be overly  
difficult.

Of course you may choose to use attributes instead of elements if you  
prefer to (I do not :-P )
'word' type can also be made abstract and extended if nouns or verbs  
require additional info to be sent.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.