0

I have a script that reads values 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

3
  • What does the data from the database look like? Have you checked if there even are any data retrieved? Commented Jun 2, 2011 at 12:05
  • 3
    Please (a) narrow your code to the smallest example that still shows the problem, (b) post it here, where we know it won't disappear, so this question will stay useful in the future, and (c) post the result file you're getting so we know what you mean by "with no values". Thanks! Commented Jun 2, 2011 at 12:05
  • @Ancide the data is ok. checked the results. Commented Jun 2, 2011 at 12:27

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Darn. I did't notice it had been solved already. You should have accepted your own answer.
1

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()

2 Comments

Or use $doc->save('document.xml'); to save to a file. (See php.net/manual/en/domdocument.save.php)
i tried both. if i use echo $doc->saveXML(); nothing is printed out. if i use $doc=>save('document.xml') a file is written but with just the tags with no values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.