/**
  * Returns the contents of the request as an XML string
  * @ignore
  * @param string &$docRootXpath document root xpath
  * @param string &$docIdXpath document ID xpath
  * @param array &$envelopeParams an associative array of CPS envelope parameters
  * @return string
  */
 public function getRequestXml(&$docRootXpath, &$docIdXpath, &$envelopeParams, $resetDocIds)
 {
     unset($this->_requestDom);
     $this->_requestDom = new DomDocument('1.0', 'utf-8');
     $root = $this->_requestDom->createElementNS('www.clusterpoint.com', 'cps:request');
     $this->_requestDom->appendChild($root);
     // envelope parameters first
     foreach ($envelopeParams as $name => $value) {
         if ($value) {
             $root->appendChild($this->_requestDom->createElement('cps:' . $name, $this->getValidXmlValue($value)));
         }
     }
     $contentTag = $root->appendChild($this->_requestDom->createElement('cps:content'));
     // content tag text parameters
     foreach ($this->_textParams as $name => $values) {
         if (!is_array($values)) {
             $values[0] = $values;
         }
         foreach ($values as $value) {
             $contentTag->appendChild($this->_requestDom->createElement($name, $this->getValidXmlValue($value)));
         }
     }
     // special fields: query, list, ordering
     foreach ($this->_rawParams as $name => $values) {
         if (!is_array($values)) {
             $values[0] = $values;
         }
         foreach ($values as $value) {
             $fragment = $this->_requestDom->createDocumentFragment();
             $fragment->appendXML('<' . $name . ' xmlns:cps="www.clusterpoint.com">' . $value . '</' . $name . '>');
             $contentTag->appendChild($fragment);
         }
     }
     if (!is_null($this->_changesets)) {
         $xmlContent = '';
         if (count($this->_changesets) > 1) {
             foreach ($this->_changesets as $cs) {
                 $xmlContent .= '<cps:changeset>';
                 $xmlContent .= $cs->renderXML($docRootXpath, $docIdXpath, $this);
                 $xmlContent .= '</cps:changeset>';
             }
         } else {
             if (count($this->_changesets) == 1) {
                 $xmlContent .= $this->_changesets[0]->renderXML($docRootXpath, $docIdXpath, $this);
             }
         }
         if (strlen($xmlContent) > 0) {
             $tmpDoc = new DOMDocument();
             $tmpDoc->loadXML('<fakedoc xmlns:cps="www.clusterpoint.com">' . $xmlContent . '</fakedoc>');
             foreach ($tmpDoc->documentElement->childNodes as $child) {
                 $domNode2 = $this->_requestDom->importNode($child, true);
                 $contentTag->appendChild($domNode2);
             }
         }
     }
     // extra XML content
     if (!is_null($this->_extraXmlParam)) {
         $tmpDoc = new DOMDocument();
         $tmpDoc->loadXML('<fakedoc xmlns:cps="www.clusterpoint.com">' . $this->_extraXmlParam . '</fakedoc>');
         foreach ($tmpDoc->documentElement->childNodes as $child) {
             $domNode2 = $this->_requestDom->importNode($child, true);
             $contentTag->appendChild($domNode2);
         }
     }
     // documents, document IDs
     foreach ($this->_documents as $id => $doc) {
         $subdoc = new DOMDocument();
         $subroot = NULL;
         $loadForEach = false;
         if (is_string($doc)) {
             $res = @$subdoc->loadXML($doc);
             if ($res === FALSE) {
                 throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter - unable to parse XML', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
             }
         } else {
             if (is_array($doc)) {
                 // associative array
                 $loadForEach = true;
             } else {
                 if (is_object($doc)) {
                     if ($doc instanceof SimpleXMLElement) {
                         // SimpleXML
                         $loadForEach = true;
                     } else {
                         if ($doc instanceof DOMNode) {
                             // DOM
                             $subdoc = $doc;
                         } else {
                             if ($doc instanceof stdClass) {
                                 // stdClass
                                 $loadForEach = true;
                             } else {
                                 throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
                             }
                         }
                     }
                 } else {
                     if (is_null($doc)) {
                         // just document IDs - no doc integration required
                     } else {
                         throw new CPS_Exception(array(array('long_message' => 'Invalid request parameter', 'code' => ERROR_CODE_INVALID_PARAMETER, 'level' => 'REJECTED', 'source' => 'CPS_API')));
                     }
                 }
             }
         }
         if (!($subroot = $subdoc->documentElement)) {
             $subroot = $subdoc->createElement($docRootXpath);
             $subdoc->appendChild($subroot);
         }
         if ($loadForEach) {
             CPS_Request::_loadIntoDom($subdoc, $subroot, $doc);
         }
         if ($resetDocIds) {
             // integrating ID into the document
             CPS_Request::_setDocId($subdoc, $subroot, $id, $docIdXpath);
         }
         //importing subdoc
         $reqNode = $this->_requestDom->importNode($subdoc->documentElement, true);
         $contentTag->appendChild($reqNode);
     }
     $xml = $this->_requestDom->saveXML();
     unset($this->_requestDom);
     return $xml;
 }