This question already has an answer here:
When parsing an XML array like:
<?xml version="1.0" encoding="utf-8"?>
<Products>
<Product>
<Code>ABC-1001</Code>
<Brand>ZCOM</Brand>
</Product>
</Products>
I get an output of:
Array
(
[0] => Array
(
[Code] => AP1024-DDRII640
[Brand] => ZCOM
)
}
But when the XML is like:
<?xml version="1.0" encoding="utf-8"?>
<Products Code="ABC-1001">
<Product>
<Code><![CDATA[ABC-1001]]></Code>
<Brand><![CDATA[ZCOM]]></Brand>
</Product>
</Products>
It returns:
array
0 =>
array (size=12)
'@attributes' =>
array (size=1)
'Code' => string 'ABC-1001' (length=8)
'Code' =>
array (size=0)
empty
'Brand' =>
array (size=0)
empty
This is how the XML is parsed from a URL:
$updateUrl = file_get_contents('http://www.someplace/xmlfeed/xml.cfm?asd=12345&uhg=9999');
$updateXml=<<<XML
$updateUrl
XML;
$updateXmlObject=json_decode(json_encode((array) simplexml_load_string($updateXml)), 1);
$updatePHPArray=$updateXmlObject['Product'];
And:
var_dump($updatePHPArray);exit;
Gives the output as above.
Now, why am I getting empty values in the second instance and how could I remedy this without access to the XML source?
</div>