View Full Version : DOMDocument Problem

10-31-2006, 07:00 PM

I am following a tutorial from a an Ajax/PHP book. I have written a script the generates an xml document. I keep getting the following error when I try to open the script in a browser (even when I download the code from the support site):

XML Parsing Error: junk after document element
Location: http://hapuk.coreware.co.uk/test/aj...php/phptest.php
Line Number 2, Column 1:<b>Warning</b>: domdocument() expects at least 1 parameter, 0 given in <b>/home/chris/happenin/test/ajax/foundations/php/phptest.php</b> on line <b>5</b><br />

ie6 says:

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


Only one top level element is allowed in an XML document. Error processing resource 'http://hapuk.coreware.co.uk/test/ajax/...

<b>Warning</b>: domdocument() expects at least 1 parameter, 0 given in <b>/home/chris/happenin/test/ajax/...

The code that is causing the error is:

// set the output content type as xml
header('Content-Type: text/xml');
// create the new XML document
$dom = new DOMDocument();

I'm assuming that there must be something wrong with the php installation on the server. Anybody got any ideas?

10-31-2006, 07:13 PM
which version of PHP are you using? with 5.1.6 I get no error, but google seems to suggest there might be problems with previous versions, particualrly with regards to the DOM and DOMXML extensions (the latter of which is deprecated) not playing nicely with one another.

10-31-2006, 07:30 PM
PHP Version 4.4.0

Build Date Apr 12 2006 15:16:56

What do you suggest I do?

Thanks a lot

10-31-2006, 09:31 PM
I am not sure if this is a PHP version problem or not. It could well be something to do with your php.ini configuration, or it could well be something else.

To solve this problem the easy way, I would suggest that you install an already packaged configuration of PHP, Apache2, and MySql.

If you are working on a Windows machine, you download and install WAMP (http://www.wampserver.com/en/), which comes bundled with PHP5, Apache2, MySQL5, PhpMyAdmin, SQLite, SQLiteAdmin.

I have this running on local machine when I am developing websites and it works like a charm. You can also download PHP4 add-on, which will allows you to switch between PHP4 and PHP5 when developing websites. Can be very handy when developing websites for a specific server.

If you are working on Linux/Mac machine, I suggest you download and install Apache Friends (http://www.apachefriends.org/en/index.html). There are lot of add-ons there as well. such as Tomcat Mod_JK module, which allows you to configure Apache and Tomcat to work together.

I hope that helps.

All the best

10-31-2006, 09:44 PM
Thanks a lot for your help. Much appreciated. I have used WAMP locally before. The problem is that I am working on a rented server and the owners are notoriously unresponsive. I just wanted to see if there was a workaround before I approached them. I'm assuming that the suggested solutions all require full access to the server which I don't have. Nevermind. Thanks again for your help