Schema "anyType" in WSF/PHP

Tuesday, February 26, 2008

Have you seen any schema that contain elements in 'anyType' like this,
       <xsd:schema elementFormDefault="qualified" targetNamespace="http://www.wso2.org/php">
<xsd:element name="echoString">

<xsd:complexType>
<xsd:sequence>
<xsd:element name="inMessage" type="xsd:anyType"/>

</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="echoStringResponse">
<xsd:complexType>

<xsd:sequence>
<xsd:element name="returnVal" type="xsd:anyType"/>
</xsd:sequence>

</xsd:complexType>
</xsd:element>
</xsd:schema>

This type of schemas allow users to set any types at run-time. Now WSF/PHP allows users to use this facility in PHP. For an example,
So if any one want to build the following payload,

<echostring xmlns="http://www.wso2.org/php">
<inmessage>
code and string
</inmessage>
</echostring>

You can just use following array to generate this,
$res = $proxy->echoString(array("inMessage" => "code and string"));

or using the classmap,

class echoString
{
public $inMessage;
}

$echostr = new echoString();

$echostr->inMessage = "test1";

$proxy->echoString($echostr);
Similarly you will be able handle the response..

1 comment:

Music Man said...

Thanks for example. My question is can the value of an element of type "anyType" be a complexType? Your example shows jsut setting it to a string, which works in my testing. In my case the element that is anyType may be any number of complex types and I am wondering how to do this, especially in wsdl mode.