Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple PHP script to create XML file, not working; blank screen 1

Status
Not open for further replies.

artguy

Technical User
Feb 2, 2001
117
US
I edited this little bit of code to test to see why writing to an XML file using DOM/XML in PHP is not working and I get no errors nor any sort of result (like an xml file). I checked and the directory is CHMOD 777 if that matters.

Any ideas would be appreciated.

Code:
<?php
$xmlDocument = domxml_new_doc('1.0');
$documentElement = $xmlDocument->create_element('forest');
$xmlDocument->append_child($documentElement);
$tree = $xmlDocument->create_element('tree');
$name = $xmlDocument->create_element('name');
$name->append_child($xmlDocument->create_text_node('Oak'));
$tree->append_child($name);
$documentElement->append_child($tree);
$xmlDocument->dump_file('test2005.xml', FALSE, TRUE);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<p>
<a href="test2005.xml">test XML file</a>
</p> 
</body>
</html>
 
Absolutely nothing. I added 2 echos one before the PHP code and one after.

Code:
<?php
echo "Begin";
$xmlDocument = domxml_new_doc('1.0');
$documentElement = $xmlDocument->create_element('forest');
$xmlDocument->append_child($documentElement);
$tree = $xmlDocument->create_element('tree');
$name = $xmlDocument->create_element('name');
$name->append_child($xmlDocument->create_text_node('Oak'));
$tree->append_child($name);
$documentElement->append_child($tree);
$xmlDocument->dump_file('test2005.xml', FALSE, TRUE);

print_r ($xmlDocument);
echo "End";
?>

I get the "Begin" but nothing else. Would something not be setup properly on the server, perhaps, that I could ask my host about? Or is it just the code?

Thanks for your help.
 
What are the values in your php.ini for display_errors and error_reporting?

What happens if you edit the script thusly:

Code:
<?php
echo "Begin";
$xmlDocument = domxml_new_doc('1.0');
echo "1";
$documentElement = $xmlDocument->create_element('forest');
echo "2";
$xmlDocument->append_child($documentElement);
echo "3";
$tree = $xmlDocument->create_element('tree');
echo "4";
$name = $xmlDocument->create_element('name');
echo "5";
$name->append_child($xmlDocument->create_text_node('Oak'));
echo "6";
$tree->append_child($name);
echo "7";
$documentElement->append_child($tree);
echo "8";
$xmlDocument->dump_file('test2005.xml', FALSE, TRUE);
echo "9";

print_r ($xmlDocument);
echo "End";
?>

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
That's one way to see where it dies. Good thinking. (Not sure why I didn't think of that...)

I get:
Begin12345.

The settings you asked about returned this:
display_errors =
error_reporting = 2047

I am definitely new at PHP, but can I change the settings using ini_set? If so, do I change them now and then change them back when the page is live?

Thanks again for your help.
 
Changes made to php.ini settings via ini_set() are only good for that run of the script. The function does not make permanent changes to your PHP configuration.

Try changing that display_errors value to 1 and see what you get.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
WOOOHOOOO!!! Errors never looked so beautiful!

Code:
Begin12
Warning: domnode::append_child() expects parameter 1 to be object, null given in E:\WEB\harieonline\admin\test2.php on line 13
345
Fatal error: Call to a member function append_child() on a non-object in E:\WEB\harieonline\admin\test2.php on line 19

That gives me something to go by. I'll see if I can do some reasearch using these errors and see what comes up.

Thanks for your help!

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top