I am trying to parse the XML Part of the response with Simplexml without losing the "role" informations like "Komponist" or "Künstler" .
<itemattributes xml:lang="de-DE" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<ns2:binding>Audio CD</ns2:binding>
<ns2:brand>MEYER,SABINE/VARIOUS</ns2:brand>
<ns2:creator role="Künstler">Meyer,Sabine</ns2:creator>
<ns2:creator role="Künstler">Various</ns2:creator>
<ns2:creator role="Komponist">Mozart</ns2:creator>
<ns2:creator role="Komponist">Stamitz</ns2:creator>
<ns2:creator role="Komponist">Weber</ns2:creator>
<ns2:creator role="Komponist">Krommer</ns2:creator>
</ns2:itemattributes>
I have tried this:
$nodeList = $attributeSets->getAny();
foreach ($nodeList as $domNode){
$domDocument = new DOMDocument();
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
$xmlData = $domDocument->saveXML($domDocument->importNode($domNode,true));
}
//$xmlData = str_replace("ns2:", "", $xmlData);
$xmlData = new SimpleXMLElement($xmlData);
But if I do not replace the ns2 attributes, I can not parse the xml. And with uncommenting the line the role attributes are gone:
SimpleXMLElement Object
(
[Binding] => Audio CD
[Brand] => MEYER,SABINE/VARIOUS
[Creator] => Array
(
[0] => Meyer,Sabine
[1] => Various
[2] => Mozart
[3] => Stamitz
[4] => Weber
[5] => Krommer
)
)
I would like to know, how I can hold these Attributes and maybe in the end how I could get the whole XML to an associative array.