url = $url; $this->requestXML = $webapi = new SimpleXMLElement(''); $verify = $webapi->addchild('verify'); $verify->addChild('username', $username); $verify->addChild('apikey', $apikey); } // __construct function add_request( SimpleXMLElement $newRequest ) { $webapi = $this->requestXML; //$request = $webapi->addChild('request'); $this->append_tree($webapi, $newRequest); } function append_tree( $root, $child ) { // Create new DOMElements from the two SimpleXMLElements $domroot = dom_import_simplexml($root); $domchild = dom_import_simplexml($child); // Import the into the dictionary document $domchild = $domroot->ownerDocument->importNode($domchild, TRUE); // Append the to in the dictionary $domroot->appendChild($domchild); } function request() { $xml = $this->requestXML->saveXML(); $opts = array ( 'http' => array ( 'method' => "POST", 'content' => $xml, 'timeout' => 5, 'header' => "Content-Type: text/xml; charset=utf-8" ) ); $context = stream_context_create ( $opts ); $content = ''; $fp = fopen ( $this->url, 'r', false, $context ); if ($fp) { while (($buffer = fgets($fp)) !== false) { $content .= $buffer; } if (!feof($fp)) { echo "Error: unexpected fgets() fail\n"; } } //~ ob_start(); //~ fpassthru ( $fp ); //~ $content = ob_get_contents(); //~ ob_end_clean(); $this->responseXML = new SimpleXMLElement($content); fclose ( $fp ); } // request function requestXML() { return $this->requestXML; } // requestXML function responseXML() { return $this->responseXML; } // responseXML function __destruct() { }// __destruct } // WebAPI ?>