UPDATE
I added some logging and my first log, the response, is returning the XML. But after I put the response in simplexml_load_string
and then log that variable, it is empty in my log.
$client = new Client();
$res = $client->request('GET', $url);
log_info($res->getBody()-getContents());
$orders = simplexml_load_string($res->getBody()->getContents());
log_info($orders);
-------
------
Original Question
I am trying to parse the XML at the below here using SimpleXML. In my code, I have:
$orders = simplexml_load_string($res->getBody()->getContents());
$orders->getNamespaces(true);
foreach ($orders->TrackInfo as $order) {
// logic
}
This was working for me for the last few days but now I am getting the following error Error: Call to a member function getNamespaces() on boolean
. Not sure what I am doing wrong here.
XML
<?xml version="1.0" encoding="UTF-8"?>
<TrackResponse>
<TrackInfo ID="9405509205328001086959">
<Error>
<Number>-2147219283</Number>
<Description>A status update is not yet available on your Priority Mail<SUP>&reg;</SUP> package. It will be available when the shipper provides an update or the package is delivered to USPS. Check back soon. Sign up for Informed Delivery<SUP>&reg;</SUP> to receive notifications for packages addressed to you.</Description>
<HelpFile />
<HelpContext />
</Error>
</TrackInfo>
</TrackResponse>