开发者

Php writes XML file with no values

I have a script that reads va开发者_开发百科lues from a mysql database. With the values received i want to make a XML file.

The file is written but with no values. I can't figure it out. Here is the complete source code: http://www.segasiauto.ro/tmp/writexml.txt

Can someone help?

Thanks, Sebastian

EDIT

Solved. There was a problem with the array. I added the data directly to createNodeText


Look carefully what you're doing:

  $product[] = array(
  'id' => $id,
  'name' => $tip,
  'category' => $tip_produs,
  'model' => $tip_imp,
  'keywords' => $keywords,
  'price' => $pret,
  'available' => "1",
  'canBeOrderedOnline' => "0",
  'details' => $details,
  'pictures' => "picture",
  'currency' => $valuta,
  );    

and then

$doc->createTextNode( $product['id'] ));

will never get you want you want. Of course it is empty. There is nothing in there.


The problem is at the end of your file. You use:

$doc->saveXML('document.xml');

That does not output anything, the function returns a xml string. In order to send the xml string to your browser you should echo it:

echo $doc->saveXML('document.xml');

See also DOMDocument::saveXML()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜