cleey
望着那一丝海线,若隐若现。落日下的海霞,数不尽的美,看不完的醉
php解析soap xml

php解析 soap协议的 xml 如下,主要用到替换相关字符,保持xml的格式

<?php
$info = <<< EOL
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:Spider="urn:http://service.sina.com.cn/spider">
<SOAP-ENV:Body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Spider:PostDocument>
<document xsi:type="Spider:Document">
<channel xsi:type="xsd:string">新闻</channel>
<origin xsi:type="xsd:string">山西晚报</origin>
<title xsi:type="xsd:string">明年起欠税纳税人将被曝光</title>
<url xsi:type="xsd:anyURI">http://www.daynews.com.cn/mag4/20041027/ca125374.htm</url>
<datetime xsi:type="xsd:dateTime">2004-10-27T03:08:28Z</datetime>
<category xsi:type="xsd:string">今日热点</category>
<origin-datetime xsi:type="xsd:string">2004-10-27T03:08:28Z</origin-datetime>
<content xsi:type="xsd:string">&lt;p&gt;  据新华社电记者26日从国家税务总局获悉,从2005年1月1日起,税务机关将按期在办税场所或广播、电视、报纸、期刊、网络等新闻媒体上公告纳税人欠缴税款情况。&lt;/p&gt;
</content>
</document>
</Spider:PostDocument>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
EOL;

// $path = '/Users/chenglin07/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/4c31f52f3e5518a6b1f19cf06daa2669/Message/MessageTemp/8fd9bb5d7697cd3d8dcacac683668066/File/200410272033569.xml';
// $info = file_get_contents($path);
// $info = iconv('GB2312', 'UTF-8', $info);

$info = str_ireplace(['SOAP-ENV:', 'SOAP:'], '', $info);
$info = str_ireplace(['Spider:PostDocument'], 'spider', $info);
$xml = simplexml_load_string($info);

$obj = (array)$xml->Body->spider->document;

$title = $obj['title'];
$channel = $obj['channel'];
var_dump($title,$channel);

注意替换的以下非标转的的xml

SOAP-ENV:
SOAP:
Spider:PostDocument

结果如下:

string(36) "明年起欠税纳税人将被曝光"
string(6) "新闻"
<< 上一篇 kafka可视化管理工具 Kafka Manager centos7 内核升级 下一篇 >>
文章标签
随意 | Created At 2014 By William Clinton | 蜀ICP备14002619号-4 |