Example #1
0
 /**
  * Method returning the xml representation of this class
  *
  * @return SimpleXML
  */
 public function toXml()
 {
     $soapNamespace = $this->_version === self::SOAP_1_2 ? self::NS_SOAP_1_2 : self::NS_SOAP_1_1;
     $nsString = 'xmlns:env="' . $soapNamespace . '"';
     foreach ($this->_namespaces as $key => $ns) {
         if ($key > 0) {
             $nsString .= sprintf(' xmlns:urn%d="%s"', $key, $ns);
         } else {
             $nsString .= sprintf(' xmlns:urn="%s"', $ns);
         }
     }
     $message = sprintf('<env:Envelope %s></env:Envelope>', $nsString);
     $xml = new SimpleXML($message);
     if (count($this->_headers)) {
         $header = $xml->addChild('Header')->addChild('context', null, 'urn:zimbra');
         foreach ($this->_headers as $name => $value) {
             $header->addChild($name, $value);
         }
     }
     $body = $xml->addChild('Body');
     $body->append($this->_body, $this->_request->getXmlNamespace());
     return $xml;
 }