xml_parse函数的问题.烦请唠叼等高手解释一下.

coolstr 2005-08-24 10:12:50
手册上的解释.
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 )

问题:
没有执行这个函数之前还是正确的,执行完后就乱码.什么原因呢?
...全文
393 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
coolstr 2005-08-25
  • 打赏
  • 举报
回复
我已知道解决该问题的办法.谢谢大家帮忙.结贴.

详细解决方法可以到以下地址查看.
PHP调用.net的webservice 中文乱码解决方案
http://coolstr.cnblogs.com/archive/2005/08/25/222440.html

coolstr 2005-08-24
  • 打赏
  • 举报
回复
我在得到http头部信息的时候得到:
$headers:Array ( [server] => Microsoft-IIS/5.0 [date] => Wed, 24 Aug 2005 03:42:05 GMT [x-powered-by] => ASP.NET [x-aspnet-version] => 1.1.4322 [cache-control] => private, max-age=0 [content-type] => text/xml; charset=utf-8 [content-length] => 376 )

======================================
$this->xml_encoding 的值就是 从头部中取出来的.

有办法改变.net头部信息的charset值吗?

coolstr 2005-08-24
  • 打赏
  • 举报
回复
我打印出$xml的数据.在utf8下显示是正常的.

我的webservice是用.net编写的.

而且我发现我只要把nusoap.php中的
$this->parser = xml_parser_create($this->xml_encoding);
这个时候$this->xml_encoding的值为:UTF-8

改成:
$this->parser = xml_parser_create('ISO-8859-1');
后面的代码不用更改.
就完全没有问题了,中文也不会出现乱码.
xuzuning 2005-08-24
  • 打赏
  • 举报
回复
xml_parse只能处理utf-8编码的数据
显然你的$xml不是utf-8编码的,因为有“Hello World 恭喜.Input”
Meteorlet 2005-08-24
  • 打赏
  • 举报
回复
类似这样的:
Response.Content-type = "text/html;charset=UTF-8";
GaoXX 2005-08-24
  • 打赏
  • 举报
回复
如何得到http头

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧