How to process XML containing custom namespaces using SimpleXML?

I am wondering how to parse the values ​​in XML that seem to have: on their behalf. I used:

$response   = file_get_contents($url);
$data = simplexml_load_string($response);

then do:

foreach($data->item as $key => $current){

However, one of the last feeds I received has colons in the feed name, as shown in the example below:

<item>
  <title>foo</title>
  <description>foo</description>           
  <ccc:fid>10</ccc:fid>
  <ccc:bid>6</ccc:bid>
 </item>

When I try to create $ current-> ccc: php rate does not get to happiness (rightfully). Is there any way around this?

+2
source share
3 answers

using ccc: fid is a namespace extension that must be declared in xml in order to be able to use it in libraries like simplexml.

:

, , .

+2

, XML. . SimpleXMLElement PHP , :

$current->fid;

, :

$current->fid->getNamespaces();
+3

"ccc" is a namespace - you should be able to do

$current->fid
+2
source

All Articles