The Data:
<Relationships>
<ns2:VariationChild>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>B002KT3XQC</ASIN>
</MarketplaceASIN>
</Identifiers>
<ns2:Color>Black</ns2:Color>
<ns2:Size>Small</ns2:Size>
</ns2:VariationChild>
<ns2:VariationChild>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>B002KT3XQW</ASIN>
</MarketplaceASIN>
</Identifiers>
<ns2:Color>Black</ns2:Color>
<ns2:Size>Medium</ns2:Size>
</ns2:VariationChild>
</Relationships>
The Code:
$data = simplexml_load_string($response);
foreach($data->GetMatchingProductResult AS $GetMatchingProductResult){
$Product = $GetMatchingProductResult->Product;
$Relationships = $Product->Relationships;
foreach($Relationships->children('ns2', true)->VariationChild AS $VariationChild){
$Identifiers = $VariationChild->Identifiers;
$MarketplaceASIN = $Identifiers->MarketplaceASIN;
$MarketplaceId = $MarketplaceASIN->MarketplaceId;
$ASIN = $MarketplaceASIN->ASIN;
echo "$ASIN<br />";
}
}
This echos the returns, but no data so it is actually looping through the XML. However nothing I try will actually return data in the $ASIN variable. Is this because of the namespace, or simpleXML, or am I missing something else entirely?
edit: other methods tried
foreach($Relationships->children('http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd', true)->VariationChild AS $VariationChild){
$Identifiers = $VariationChild->Identifiers;
$MarketplaceASIN = $Identifiers->MarketplaceASIN;
$MarketplaceId = $MarketplaceASIN->MarketplaceId;
$ASIN = $MarketplaceASIN->ASIN;
echo "[$ASIN]<br />";
}
$test = new SimpleXMLElement($response);
$test->registerXPathNamespace('ns2', 'http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd');
$variations = $test->xpath('//ns2:VariationChild');
foreach($variations AS $vars){
print_r($vars);
}
Neither seems to even loop the data.