Marcus Sá 0 Denunciar post Postado Abril 15, 2009 Pessoal, estou tentando incluir alguns dados em um arquivo XML utilizando DOM XML, meu código está assim: $xdoc = new DomDocument; $xdoc->Load('items.xml'); $content = $xdoc->getElementsByTagName('items')->item(0); $Image = $xdoc->createElement('image'); $Path = $xdoc->createElement('path', $Var_Path); $Image = $xdoc->appendChild($Path); $Preview = $xdoc->createElement('preview', $Var_Preview); $Image = $xdoc->appendChild($Preview); $Big = $xdoc->createElement('big', $Var_Big); $Image = $xdoc->appendChild($Big); $Description = $xdoc->createElement('description', $Var_Description); $Image = $xdoc->appendChild($Description); $Title = $xdoc->createElement('title', $Var_Title); $Image = $xdoc->appendChild($Title); $content = $xdoc->appendChild($Image); // Salvo o arquivo return $xdoc->saveXML(); Mas o XML retornado não está certo, ele vem assim: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <items> <image> <path>pics/</path> <preview>1.jpg</preview> <big>1big.jpg</big> <description><![CDATA[Description text. This is HTML formated text so you can add <a href="http://www.flashden.net"><u><font color="#00c4ff">links</font></u></a> here.]]></description> <title>Title01</title> </image> </items> <path>O</path> <preview>O</preview> <big>O</big> <description>O</description> <title>O</title> Ele cria os itens certos, mas nao joga eles dentro de <image> e nao joga <image> dentro de <items> No caso o código que foi incluido ali pelo meu php foi <path>O</path> <preview>O</preview> <big>O</big> <description>O</description> <title>O</title> O resto já estava no XML e é o modelo que devo seguir... Quem pudar ajudar ai, muito obrigado! Abraços! Compartilhar este post Link para o post Compartilhar em outros sites
Marcus Sá 0 Denunciar post Postado Abril 15, 2009 Pessoal, problema resolvido, olhem o código certo, pra se por acaso alguém venha a precisar no futuro: $content = $xdoc->getElementsByTagName('items')->item(0); $Image = $xdoc->createElement('image'); $Path = $xdoc->createElement('path', $Var_Path); $Image -> appendChild($Path); $Preview = $xdoc->createElement('preview', $Var_Preview); $Image -> appendChild($Preview); $Big = $xdoc->createElement('big', $Var_Big); $Image -> appendChild($Big); $Description = $xdoc->createElement('description', $Var_Description); $Image -> appendChild($Description); $Title = $xdoc->createElement('title', $Var_Title); $Image -> appendChild($Title); $content -> appendChild($Image); O problema eram os appendChild que eu estava chamando $xdoc->appendChild Compartilhar este post Link para o post Compartilhar em outros sites