xml_parse函数的问题.烦请唠叼等高手解释一下.
手册上的解释.
xml_parse
解析 XML 文件。
语法: boolean xml_parse(int parser, string data, int [isFinal]);
返回值: 布尔值
函数种类: 资料处理
内容说明
本函数用来解析 XML 格式的文件资料。参数 parser 为解析代码。参数 data 为解析的资料区块 (chunk)。参数 isFinal 可省略,若设为 true 则系统会自动送出最后的资料部分 (piece) 给 data 参数。若无错误则返回 true 值。
不知手册上所云.........
=======================================================================
最近在搞nusoap,遇到
在下载回来的nusop的第5894行中有一段代码如下:
// Parse the XML file.
echo '<br>$this->parser : '.$this->parser;
echo '<br>$xml : '.htmlspecialchars($xml);
//if(false){
if(!xml_parse($this->parser,$xml,true)){
// Display an error message.
$err = sprintf('XML error parsing SOAP payload on line %d: %s',
xml_get_current_line_number($this->parser),
xml_error_string(xml_get_error_code($this->parser)));
$this->debug($err);
$this->debug("XML payload:\n" . $xml);
$this->setError($err);
} else {
$this->debug('parsed successfully, found root struct: '.$this->root_struct.' of name '.$this->root_struct_name);
// get final value
$this->soapresponse = $this->message[$this->root_struct]['result'];
//注意这个地方,乱码
echo '<br>Result:';
print_r($this->message[$this->root_struct]['result']);
// get header value: no, because this is documented as XML string
// if($this->root_header != '' && isset($this->message[$this->root_header]['result'])){
// $this->responseHeaders = $this->message[$this->root_header]['result'];
// }
============================================
结果如下:
$this->parser : Resource id #5
$xml : <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><HelloWorldResponse xmlns="http://tempuri.org/"><HelloWorldResult>Hello World 恭喜.Input</HelloWorldResult></HelloWorldResponse></soap:Body></soap:Envelope>
03:2
Result:Array ( [HelloWorldResult] => Hello World ??.Input )
问题:
没有执行这个函数之前还是正确的,执行完后就乱码.什么原因呢?