I have the following script saved as 'index.php':

<?php 
$implementation = new DOMImplementation();
$doctype = $implementation->createDocumentType('html');
$document = $implementation->createDocument('http://www.w3.org/1999/xhtml', 'html', $doctype);
$head = $document->createElement('head');
$document->documentElement->appendChild($head);
echo $document->saveXML();

Now when I run the script, I get nothing at all (i.e. no source XML is being received by the browser). Error reporting is set to E_ALL | E_STRICT in php.ini yet the browser shows nothing. To test my installation, a quick "echo 'hello world' proved PHP and my server are working". Are there any instances where PHP will output nothing at all? If so, are there any ways to go about debugging them?

Thanks in advance for any help/tips/pointers:)

Recommended Answers

All 3 Replies

I think it might be this line.

$document->documentElement->appendChild($head);

maybe change it to:

$document->appendChild($head);

You didn't get an error because the code is OK, but it just isn't doing what you expected

I think it might be this line.

$document->documentElement->appendChild($head);

maybe change it to:

$document->appendChild($head);

You didn't get an error because the code is OK, but it just isn't doing what you expected

Thanks for the response JRM. Unfortunately:

$document->documentElement->appendChild($head);

...is the correct way to append a child to the root element.

$document->appendChild($head)

...will add an element as a sibling, rather than child of the root element. Even when I try:

<?php 
$implementation = new DOMImplementation();
$doctype = $implementation->createDocumentType('html');
$document = $implementation->createDocument('http://www.w3.org/1999/xhtml', 'html', $doctype);
echo $document->saveXML();

I get nothing from the server at all. I'm going to keep trying and will post any results I find here, just in case someone is viewing this post with a similar problem. Disclaimer: YMMV :-P

Classic case of poor documentation. Although the PHP5 manual states:

There is no installation needed to use these functions; they are part of the PHP core. DOM support may be disabled with --disable-dom.

...this is simply not true. One needs to manually install PHP-XML support also; now the script works flawlessly. I've filed this as a bug at http://bugs.php.net/bug.php?id=51589&thanks=4.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.