note 86519 deleted from book.soap by danbrown

From: Date: Wed, 22 Oct 2008 22:54:07 +0000
Subject: note 86519 deleted from book.soap by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-145623@lists.php.net to get a copy of this message
Note Submitter: beau dot scott at gmail dot com Reason: integrated ---- If you've been trying to send null to a service that considers empty property tags as empty strings rather than null, here's an extending class that fixes this using xsi:nil: <?php class XSoapClient extends SoapClient { const SOAP_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/"; const XSI_NS = "http://www.w3.org/2001/XMLSchema-instance"; protected $mustParseNulls = false; public function __doRequest($request, $location, $action, $version, $one_way = null) { if($this->mustParseNulls) { $this->mustParseNulls = false; $dom = new DOMDocument("1.0"); $dom->loadXML($request); $root = $dom->documentElement; $bodies = $dom->getElementsByTagNameNS(self::SOAP_ENV_NS, 'Body'); $body = $bodies->item(0); $params = $body->childNodes; $i = 0; while($child = $body->childNodes->item($i++)) { if(!$child->hasChildNodes()) { $child->setAttribute("xmlns:phpsoapclientsucks", self::XSI_NS); $child->setAttribute("phpsoapclientsucks:nil", "true"); } } $request = $dom->saveXML(); } return parent::__doRequest($request, $location, $action, $version, $one_way); } public function __call($method, $params) { if(count($params) == 0) { $this->mustParseNulls = true; } else { foreach($params as $param) { if($param === null) { $this->mustParseNulls = true; break; } } } return parent::__call($method, $params); } } ?>

« previous php.notes (#145623) next »