gpt4 book ai didi

xml - 使用 simplexml_load_file 解析 XML 文件返回空对象

转载 作者:可可西里 更新时间:2023-11-01 00:09:42 26 4
gpt4 key购买 nike

 <?xml version="1.0" ?> 
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
<aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11">
<aws:OperationRequest>
</aws:OperationRequest>
<aws:UrlInfoResult>
<aws:Alexa>
<aws:TrafficData>
<aws:DataUrl type="canonical">google.com/</aws:DataUrl>
<aws:Rank>1</aws:Rank>
</aws:TrafficData>
</aws:Alexa>
</aws:UrlInfoResult>
<aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
<aws:StatusCode>Success</aws:StatusCode>
</aws:ResponseStatus>
</aws:Response>
</aws:UrlInfoResponse>

我想要解析的只是来自这个 xml 文档的排名。在尝试时,我正在做的是......

        $xml= simplexml_load_file("path of the file saved");
echo $xml->Response->UrlInfoResult->Alexa->TrafficData->Rank;

但我这样做时出错。它说

 Notice: Trying to get property of non-object in C:\wamp\www\SEO Stats[Only Testing]\Tools\web_worth.php on line 13

错误在这一行

 echo $xml->Response->UrlInfoResult->Alexa->TrafficData->Rank;
this line is referred as line no 13..

最佳答案

解析器返回一个空对象,因为根据 documentation你必须指定带前缀的命名空间 - 例如你想使用类似的东西:

simplexml_load_file('/path/to/file.xml', null, null, 'aws', true);

working example

关于xml - 使用 simplexml_load_file 解析 XML 文件返回空对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15787198/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com