October 25th, 2008WSF/PHP WSDL Mode - Handling XML Schema Arrays
In XML Schema we declare an array or a multiple occurrence of a schema element by setting its maxOccurs attribute to a value greater than 1 or to the value “unbounded” in a case of no maximum boundary.
<xs:element maxOccurs="unbounded"
minOccurs="0"
name="params"
nillable="true"
type="xs:int"/>
If you generate PHP code to such a schema using wsdl2php tool, you will get a code for the class variable named “params” similar to this.
/** * @var array[0, unbounded] of int */ public $params;
So if you have a variable (say $object) for the object of this class you can fill the “params” field like this,
$object->params = array(1, 5, 8);
This will create the xml with the expected array of elements.
<wrapper> <params>1</params> <params>5</params> <params>8</params> </wrapper>
Not only for simple types, you can have arrays of complex types too.
<xs:element maxOccurs="unbounded"
minOccurs="0"
name="params"
nillable="true"
type="tns:MyComplexType"/>
Instead of giving simple integers like earlier case, this time you will feed the “params” variable with an array of PHP objects of ‘MyComplexType’ class.
$obj1 = new MyComplexType(); /* feeding data to obj1 variables */ $obj2 = new MyComplexType(); /* feeding data to obj2 variables */ $obj3 = new MyComplexType(); /* feeding data to obj3 variables */ $object->params = array($obj1, $obj2, $obj3);
This will create a xml containing array of params similar to this,
<wrapper> <params> <elementx/> <!-- elements in the MyComplexType type --> <elementy/> </params> <params> ... <!-- elements in the MyComplexType type --> </params> <params> ... <!-- elements in the MyComplexType type --> </params> </wrapper>
![[Ask]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/ask.png)
![[Bloglines]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/bloglines.png)
![[del.icio.us]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/digg.png)
![[diigo]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/diigo.png)
![[dzone]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/dzone.png)
![[Facebook]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/myspace.png)
![[MyWeb]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/myweb.png)
![[Newsvine]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/newsvine.png)
![[PlugIM]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/plugim.png)
![[Reddit]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/slashdot.png)
![[Spurl]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/spurl.png)
![[StumbleUpon]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Twitter]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/twitter.png)
![[Windows Live]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://www.dimuthu.org/wp-content/plugins/bookmarkify/email.png)