Get data out of a atom feed when there are many namespace (simpleXMLELEMENT)

Good day,

I would like to know if someone know how to get the value 31636 out of the tag <os:totalResults>31636</os:totalResults> using simpleSMLELEMENT

<?xml version=‘1.0’ encoding=‘UTF-8’?>
<feed xmlns=“http://www.w3.org/2005/Atom” xmlns: os=“http://a9.com/-/spec/opensearch/1.1/” xmlns:as=“http://atomserver.org/namespaces/1.0/” xmlns:georss=“http://www.georss.org/georss” xmlns:gml=“http://www.opengis.net/gml” xml:base=“http://beta.geogratis.gc.ca/api/en/”>
<as:endIndex>27784</as:endIndex>
<os:totalResults>31636</os:totalResults>

With the following I’m getting the title, but getting access to namespace xmlns: os=“http://a9.com/-/spec/opensearch/1.1/” remains a mystery. Thanks in advance to give my some help.

$feed = new SimpleXMLElement($xml);//produce_XML_object_tree($xml);

$second_entry_title = $feed-&gt;entry[0]-&gt;title; 

echo $second_entry_title . '&lt;br/&gt;';

Hello,

Just to conclude on that topic… I have not been able to find a way to get into namespace with simpleXMLELEMENT.

It seams to be a bit tricky getting there.

As the feed was also available in json, I have decided to use it instead. It is much more simple.

It looks like :

$json = file_get_contents($url); 
$obJson = json_decode($json);
return  $obJson-&gt;{'count'}; 

Thanks anyway :slight_smile:

the only way i know is by replacing the : like so:

$xmlString = str_replace('os:total', 'os_total', $xmlString);
$xml = simplexml_load_string($xmlString);
echo (string)$xml->os_totalResults;

See SimpleXMLElement::registerXPathNamespace.