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

From: Date: Wed, 13 Jun 2007 12:27:09 +0000
Subject: Re: [SOAP] xsd:choice maxOccurs=unbounded, and element order
References: 1 2 3 4 5  Groups: php.soap 
Request: Send a blank email to php-soap+get-2562@lists.php.net to get a copy of this message
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.

« previous php.soap (#2562) next »