I have a problem that someone might be able to help me with. I am not an experienced programmer but I am ok to have advanced answers so I can learn more.
I download an xml file, open it and read it. When a specific condition is met I change value in that node and this works fine. But after that I'd like to write the whole node that I just changed into a new xml file and this is where I've got problems. I manage to store the last node which indicates that I am writing over existing node in the new document all the time.
This is my code:
$prodsToSave = new DOMDocument(); //my new document
$prods = new DOMDocument();
$prods = simplexml_load_file('http://urltofile.com');
foreach ($prods as $product) {
if($product->merchantCategoryName == 'CD') {
$productToSave = $product;
$productToSave->merchantCategoryName = 'Musik > CD';
$prodsToSave=$productToSave;
}
$prodsToSave->saveXML('newdocument.xml');
}
I can see why I only have one node written into the new document but I don't know how to change it so I get all my nodes in the new document?