Can anybody explain this?
foreach ($xml as $product) {
Why does this work to remove the nodes
unset ($product->itemspecific);
unset ($product->properties);
But this doesn't remove the entire element?
unset ($product);
}
EDIT:
$result = $soap->GetFeedXML( array('accessKey' => $feed) );
//Write XML data to file
$bytes = file_put_contents($file,$result->GetFeedXMLResult);
$xml = new SimpleXMLElement($result->GetFeedXMLResult);
foreach ($xml as $product) {
//Remove fluous properties
unset ($product->ebay_itemspecific);
unset ($product->StoneProperties);
unset ($product->StoneValues);
unset ($product->UserCity);
unset ($product->eBayStartingPrice);
unset ($product->ebay_quantity);
unset ($product->ebay_variation);
unset ($product->Amazon_Metal_Type);
unset ($product->Amazon_Item_Type);
unset ($product->Ebay_Category_Number);
unset ($product->DropshipUser_Zip);
unset ($product->DropshipUser_Company);
unset ($product->PayPal_Email_Address);
//Convert different product sizes into options for the single product
$x = strpos($product->StockNo,"-");
if ($x > 0) {
$stock = substr($product->StockNo,0,$x);
$size = substr($product->StockNo,$x+1);
//Find the parent
$p = $xml->xpath("ProductFeedEntity[StockNo='$stock']");
$option = $p[0]->addChild("Options")->addChild("Size");
$option->addChild("Name","Size");
$option->addChild("Value", $size);
$option->addChild("CostPrice", $product->CostPrice);
echo "<i> Added size: " . $size . "</i><br>";
THIS IS WHERE THE PROBLEM IS. I've tried with an $index and without. I've tried unset($xml[$index]) but that doesn't work either.
//Remove the sized product
unset($product[$index]);
} else
echo $product->StockNo . " - " . $product->ItemTitle . "<br>";
$index++;
}
$xml->asXml($file);
XML
<ProductFeedEntity>
<StockNo>123</StockNo>
<MoreNodes>XXX</MoreNodes>
<MoreNodes>XXX</MoreNodes>
</ProductFeedEntity>
<ProductFeedEntity>
<StockNo>456</StockNo>
<MoreNodes>XXX</MoreNodes>
<MoreNodes>XXX</MoreNodes>
</ProductFeedEntity>
<ProductFeedEntity>
<StockNo>456-A</StockNo>
<MoreNodes>XXX</MoreNodes>
<MoreNodes>XXX</MoreNodes>
</ProductFeedEntity>
<ProductFeedEntity>
<StockNo>789</StockNo>
<MoreNodes>XXX</MoreNodes>
<MoreNodes>XXX</MoreNodes>
</ProductFeedEntity>