here is the code:
$icmlData = file_get_contents($config['icml']);
$xmlIter = new SimpleXMLElement($icmlData);
foreach ($xmlIter->shop->offers->offer as $offer) {
$id = $offer->attributes()['id'];
$id = strval($id);
$offer->addChild('externalId', $id);
$offer->addChild('xmlId', $id);
}
$result = file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . 'icml_t.xml', $xmlIter->asXML());
I take xml from one file, try to add 2 children to each 'offer' tags and put this xml into another file, but as a result I see two identical files.
Need help.
So, I don’t know how correct it is, but also the code change helped solve the problem: