I have this xml file :
<?xml version="1.0" encoding="utf-8" ?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<item>
<!-- Basic Product Information -->
<g:id><![CDATA[FSK10]]></g:id>
<title><![CDATA[title]]></title>
<description><![CDATA[desc]]></description>
<g:product_type><![CDATA[Default Category]]></g:product_type>
<g:product_type><![CDATA[Default Category > Cat1]]></g:product_type>
<g:product_type><![CDATA[Default Category > Cat1 > Cat2]]></g:product_type>
<link><![CDATA[https://www.link.com]]></link>
<g:image_link><![CDATA[https://www.link.com/media/image.jpg]]></g:image_link>
<g:condition><![CDATA[new]]></g:condition>
<g:availability><![CDATA[in stock]]></g:availability>
<g:quantita><![CDATA[9]]></g:quantita>
<g:price><![CDATA[68.50EUR]]></g:price>
<g:brand><![CDATA[FISKARS]]></g:brand>
<g:ean><![CDATA[6411501967701]]></g:ean>
<g:mpn><![CDATA[FSK10]]></g:mpn>
<g:identifier_exists><![CDATA[TRUE]]></g:identifier_exists>
<g:shipping_weight><![CDATA[1.70kg]]></g:shipping_weight>
</item>
</rss>
When I call SimplexmlElement
in php it doesn't list all the children, it is missing the tags with the namespace g:
:
$xml = simplexml_load_string( $data );
$attributes = $item->children(); //get the rss
echo htmlentities( $xml->asXML() ) . '<br />';
foreach ( $attributes as $attr ) {
echo "$attr<br />";
}
How to list all the tags?
As @splash58 comment: you can use children
command with namespace as argument (and setting true to prefix).
Code:
$attributes = $item->children('g', true);
foreach($attributes as $atrr) {
echo "$attr<br />";
}
Full documentation can be found PHP Manual