Home  >  Article  >  Backend Development  >  一个接口,能得到返回的xml文件,怎么提取有用的内容

一个接口,能得到返回的xml文件,怎么提取有用的内容

WBOY
WBOYOriginal
2016-06-13 11:21:011292browse

一个接口,能得到返回的xml文件,如何提取有用的内容?
接口调用后,$result= 能得到以下内容:

stdClass Object
(
    [out] => 

 
 




T

)


以前做这直接读取 xml的,可这种带了一个stdClass Object(  [out] =>

不知道应该如何读到各节点内容了


------解决方案--------------------
如果你对对象操作不熟悉,可以先转换为数组,这样会方便一些。
你获取的对象很简单, $result->out 就是这个XML字符串,若是想提取其中的内容,可以尝试字符串提取,或者解析XML为对象再转数组(推荐)。
http://www.php.net/manual/zh/language.oop5.properties.php


------解决方案--------------------
直接打印
echo $result->out;

作为xml解析
$xml = simplexml_load_string($result->out);
print_r($xml);
SimpleXMLElement Object<br>(<br>    [flights] => SimpleXMLElement Object<br>        (<br>            [flight] => SimpleXMLElement Object<br>                (<br>                    [@attributes] => Array<br>                        (<br>                            [orgCity] => SHA<br>                            [departTerm] => T2<br>                            [dstCity] => CAN<br>                            [arrivalTerm] => --<br>                            [airComp] => MU<br>                            [flightno] => MU5307<br>                            [planeType] => 320<div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn