php xml-rpc远程调用

2019-04-10 13:34:25王冬梅

$this->last_opened_tag = NULL;
xml_parse($this->parser, $data);
return $this->document;
}

function open($parser, $tag, $attributes){
#echo "Opening tag $tag<br>n";
$this->data = "";
$this->last_opened_tag = $tag; #tag is a string
if(array_key_exists($tag, $this->parent)){
#echo "There's already an instance of '$tag' at the current level ($level)<br>n";
if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric
#need to make sure they're numeric (account for attributes)
$key = count_numeric_items($this->parent[$tag]);
#echo "There are $key instances: the keys are numeric.<br>n";
}else{
#echo "There is only one instance. Shifting everything around<br>n";
$temp = $this->parent[$tag];
unset($this->parent[$tag]);
$this->parent[$tag][0] = $temp;

if(array_key_exists("$tag attr", $this->parent)){
#shift the attributes around too if they exist
$temp = $this->parent["$tag attr"];
unset($this->parent["$tag attr"]);
$this->parent[$tag]["0 attr"] = $temp;
}
$key = 1;
}
$this->parent = $this->parent[$tag];
}else{
$key = $tag;
}
if($attributes){
$this->parent["$key attr"] = $attributes;
}

$this->parent[$key] = array();
$this->parent = $this->parent[$key];
array_unshift($this->parents, $this->parent);
}

function data($parser, $data){
#echo "Data is '", htmlspecialchars($data), "'<br>n";
if($this->last_opened_tag != NULL){
$this->data .= $data;
}
}

function close($parser, $tag){
#echo "Close tag $tag<br>n";
if($this->last_opened_tag == $tag){
$this->parent = $this->data;
$this->last_opened_tag = NULL;
}
array_shift($this->parents);
$this->parent = $this->parents[0];
}
}

function & XML_unserialize($xml){
$xml_parser = new XML();
$data = $xml_parser->parse($xml);
$xml_parser->destruct();
return $data;
}

function & XMLRPC_parse($request){
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_parse', "<p>Received the following raw request:</p>" . XMLRPC_show($request, 'print_r', true));
}
$data = &XML_unserialize($request);
if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){
XMLRPC_debug('XMLRPC_parse', "<p>Returning the following parsed request:</p>" . XMLRPC_show($data, 'print_r', true));
}
return $data;
}

function & XMLRPC_prepare($data, $type = NULL){
if(is_array($data)){
$num_elements = count($data);
if((array_key_exists(0, $data) or !$num_elements) and $type != 'struct'){ #it's an array
if(!$num_elements){ #if the array is emptyempty
$returnvalue = array('array' => array('data' => NULL));
}else{
$returnvalue['array']['data']['value'] = array();
$temp = $returnvalue['array']['data']['value'];
相关文章 大家在看