Laravel:使用SimpleXML名称空间问题解析XML

时间:2020-01-26 07:40:18

标签: php xml laravel simplexml

更新

我添加了一些日志记录,而我的第一个日志(响应)正在返回XML。但是,在将响应放入var attempts = 0; var randomNumber; while (randomNumber === 10) { randomNumber = (Math.random(10 - 1) + 1); attempts = attempts + 1; } document.write("It took " + attempts + " attempts"); 中并记录了该变量之后,它在我的日志中为空。

simplexml_load_string

-------

------

原始问题

我试图在下面使用SimpleXML解析XML。在我的代码中,我有:

    $client = new Client();
    $res = $client->request('GET', $url);
    log_info($res->getBody()-getContents());

    $orders = simplexml_load_string($res->getBody()->getContents());
    log_info($orders);

在最近几天为我工作,但现在出现以下错误 $orders = simplexml_load_string($res->getBody()->getContents()); $orders->getNamespaces(true); foreach ($orders->TrackInfo as $order) { // logic } 。不知道我在做什么错。


XML

Error: Call to a member function getNamespaces() on boolean

0 个答案:

没有答案