What is there in an object representing a complexType element ?
| From: | LEBUR Guillaume | Date: | Mon, 02 May 2005 14:13:34 +0000 |
| Subject: | What is there in an object representing a complexType element ? | ||
| Groups: | php.soap | ||
| Request: | Send a blank email to php-soap+get-1901@lists.php.net to get a copy of this message | ||
Hi,
I have written a sample PHP Web Service whose WSDL looks like that :
[...]
<types><xsd:schema elementFormDefault="qualified"
targetNamespace="urn:cms">
<xsd:element name="article">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="titre" type="xsd:string"/>
<xsd:element name="texte">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:any namespace="http://www.w3.org/1999/xhtml"
processContents="lax"
minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
[...]
<message name="publierRequest"><part name="parameters"
element="tns:article" /></message>
<message name="publierResponse"><part name="parameters"
element="tns:publierResponseType" /></message>
<portType name="cmsserverPortType">
<operation name="publier"><input
message="tns:publierRequest"/><output
message="tns:publierResponse"/></operation>
</portType>
<binding name="cmsserverBinding" type="tns:cmsserverPortType">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="publier">
<soap:operation soapAction="urn:cms#publier" style="document"/>
<input><soap:body use="literal"
namespace="urn:cms"/></input>
<output><soap:body use="literal"
namespace="urn:cms"/></output>
</operation>
</binding>
[...]
The "texte" element of the "article" parameter contains xhtml code, this
is why I set it as a mixed complexType containing an unbounded sequence
with any type of element in it. An example of the XML code sent to the
soap server would look like this :
[...]
<article>
<!-- a simple string -->
<titre>Title</titre>
<!-- xhtml code -->
<texte><a href="foo.com">This</a> is a text
<strong>sample</strong></texte>
</article>
[...]
The soap server contains a single function that writes the title and the
text of the article to a database :
<?php
function publier($article) {
$conn=new mysqli('localhost','root','', 'mini_cms');
$query = "INSERT INTO article (titre, texte) VALUES ('".
$article->titre ."', '". $article->texte ."')";
$result=$conn->query($query);
return $result;
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("desc.wsdl");
$server->addFunction("publier");
$server->handle();
?>
The $article->titre variable points to the title (since it is a plain
simple xsd:string), but $article->texte points to an object, probably
because it is a complex type containing text and a sequence of elements.
The problem is, I don't know the name of that object's member variables,
and I don't know how to access them.
The web service works fine but instead of "<a href="foo.com">This</a> is
a text <strong>sample</strong>" in the database text column, I get
"Object id #3".
Does anyone know how to deal with complex types like that one ? I don't
want to parse the xhtml code, just to access the "texte" element as a
block and put it in the database...
Thanks in advance,
Guillaume