createElement("produto"); $codigo = $document->createElement("codigo", $codigo); $categoria = $document->createElement("categoria", corrigirCategoria($categoria)); $link = $document->createElement("link", $link); $imagem = $document->createElement("imagem", $imagem); $nome_titulo = $document->createElement("nome_titulo", escapeXmlValue($nome_titulo)); $descricao = $document->createElement("descricao", escapeXmlValue($descricao)); $preco_real = $document->createElement("preco_real", $preco_real); $preco_desconto = $document->createElement("preco_desconto", $preco_desconto); $produto->appendChild($codigo); $produto->appendChild($categoria); $produto->appendChild($link); $produto->appendChild($imagem); $produto->appendChild($nome_titulo); $produto->appendChild($descricao); $produto->appendChild($preco_real); $produto->appendChild($preco_desconto); $specific = $document->createElement("specific"); $marca = $document->createElement("marca", $marca); $cor = $document->createElement("cor", $cor); $tamanho = $document->createElement("tamanho", $tamanho); $autor = $document->createElement("autor", $autor); $artista = $document->createElement("artista", $artista); $editora = $document->createElement("editora", $editora); $ritmo = $document->createElement("ritmo", $ritmo); $distribuidora = $document->createElement("distribuidora", $distribuidora); $sinopse = $document->createElement("sinopse", $sinopse); $loja = $document->createElement("loja", $loja); $specific->appendChild($marca); $specific->appendChild($cor); $specific->appendChild($tamanho); $specific->appendChild($autor); $specific->appendChild($artista); $specific->appendChild($editora); $specific->appendChild($ritmo); $specific->appendChild($distribuidora); $specific->appendChild($sinopse); $specific->appendChild($loja); $produto->appendChild($specific); return $produto; } $dom = new DOMDocument("1.0", "utf-8"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $content = curl_exec( $ch ); curl_close ( $ch ); //$dom = simplexml_load_string($content); //echo $content; $root = $dom->createElement("produtos"); if($myxml = simplexml_load_string($content)) { foreach ($myxml as $post) { $codigo = 'id_produto.']]>'; $categoria = $post->categoria; $link = $post->link_produto . htmlspecialchars('?utm_source=iloveecommerce&utm_medium=navegacao&utm_campaign=xml'); $imagem = $post->imagem; $nome_titulo= 'descricao.']]>'; $descricao = 'descricao.']]>'; $preco_real = $post->preco_normal; $preco_desconto = $post->preco; $marca =""; $cor=""; $tamanho=""; $autor=""; $artista=""; $editora=""; $ritmo=""; $distribuidora=""; $sinopse=""; $loja = ''; $prod = addProduto($dom, $codigo, $categoria, $link, $imagem, $nome_titulo, $descricao, $preco_real, $preco_desconto, $marca, $cor, $tamanho, $autor, $artista, $editora, $ritmo, $distribuidora, $sinopse, $loja); $root->appendChild($prod); } } else { echo 'Erro ao ler ficheiro XML'; } #adicionando no root $dom->appendChild($root); #salvando o arquivo $dom->save("vitrineTH2.xml"); #mostrar dados na tela header("Content-Type: text/xml"); print $dom->saveXML(); ?>