dokonuje zmian i uzupełniam wcześniej wygenerowanego xml-a. W części gałęzi tworzę elementy "CDATA". Jeżeli tworzę je bez pętli wszystko jest ok. Natomiast w pętli zostaje ten element wstawiony wielokrotnie w pierwszą gałąź "Entry" zamiast w kolejną nową utworzoną. Poniżej fragment kodu. Chodzi o pętle for. Proszę o wskazówkę.
$xmlObj=simplexml_load_file('test1.xml'); foreach ($xmlObj->entry as $pojedynczeTlo) { $ns_g = $pojedynczeTlo->children('http://base.google.com/ns/1.0'); $idTla=$ns_g->id; $pojedynczeTlo->addChild('g:item_group_id',$idTlaTab[1],'http://base.google.com/ns/1.0'); $pojedynczeTlo->addChild('g:size',$tabSizeAll[0][0],'http://base.google.com/ns/1.0'); $pojedynczeTlo->addChild('g:brand','Deber','http://base.google.com/ns/1.0'); $pojedynczeTlo->addChild('g:mpn',$idTla,'http://base.google.com/ns/1.0'); $domNodeTitle=dom_import_simplexml($ns_g->title); $domNodeTitle->parentNode->removeChild($domNodeTitle); $domNodePrice=dom_import_simplexml($ns_g->price); $domNodePrice->parentNode->removeChild($domNodePrice); $pojedynczeTlo->addChild('g:price',$tabSizeAll[0][1],'http://base.google.com/ns/1.0'); $domNodeGtin=dom_import_simplexml($ns_g->gtin); $domNodeGtin->parentNode->removeChild($domNodeGtin); $pojedynczeTlo->addChild('g:title',NULL,'http://base.google.com/ns/1.0'); $dom = dom_import_simplexml($ns_g->title); $cdata = $dom->ownerDocument->createCDATASection("Tło fotograficzne"); } $wstepnaIloscTel=$xmlObj->entry->count(); foreach ($xmlObj->entry as $pojedynczeTlo) { $ns_g = $pojedynczeTlo->children('http://base.google.com/ns/1.0'); $idTla=$ns_g->id; if($wstepnaIloscTel>0) {$wstepnaIloscTel=$wstepnaIloscTel-1;} else {break;} for($i=1;$i<count($tabSizeAll);$i=$i+1) { $neId=$idTla."_".$i; $Entry=$xmlObj->addChild('entry'); $Entry->addChild('g:id',$neId,'http://base.google.com/ns/1.0'); $Entry->addChild('g:availability',$ns_g->availability,'http://base.google.com/ns/1.0'); $Entry->addChild('g:condition',$ns_g->condition,'http://base.google.com/ns/1.0'); $Entry->addChild('g:description',NULL,'http://base.google.com/ns/1.0'); $dom = dom_import_simplexml($ns_g->description); $cdata = $dom->ownerDocument->createCDATASection($ns_g->description); $dom->appendChild($cdata); $Entry->addChild('g:image_link',$ns_g->image_link,'http://base.google.com/ns/1.0'); } }