XML DOM Setup with PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am using PHP version and apache2 version 2.0.54.

I am trying to install the xml dom support but am not having any luck.

Following the instructions on php.net I have done the following:

1.  Set the extensions directory in php.ini extension_dir =
2.  Loaded the xmldom module by uncommenting the line in php.ini
3.  Copied iconv.dll into C:\Windows\System32 so that it can be found
on my system's path
4.  Restarted my Apache Server

phpinfo() shows that xmldom support is enabled

DOM/XML  enabled
DOM/XML API Version  20020815
libxml Version  20611
HTML Support  enabled
XPath Support  enabled
XPointer Support  enabled
DOM/XSLT  enabled
libxslt Version  1.1.7
libxslt compiled against libxml Version  2.6.11

The code that is throwing the error is as follows:

$dom = new DOMDocument();

I am getting the error message:

PHP Warning:  domdocument() expects at least 1 parameter, 0 given in
F:\web\popup\test.php on line 11

Can anyone help point out any other setup that I may have missed?


Re: XML DOM Setup with PHP

fionathomson wrote:
Quoted text here. Click to load it

With PHP4, the version should be provided to the constructor, per example:

$dom = new DOMDocument("1.0");


Re: XML DOM Setup with PHP

Hi JW,

Thanks for your response.
As suggested I have added the version to the constructor.  I am now
getting a new error message:

Warning: domdocument(): Start tag expected, '<' not found in test.php
on line 4

The PHP file is as follows:


    $doc = new DOMDocument("1.0");

Can you suggest anything else to try?

Re: XML DOM Setup with PHP

fionathomson wrote:
Quoted text here. Click to load it

It appears that the implementation doesn't follow the documentation: the  
first argument supplied must be a valid xml document.

The following appears to work fine:

$dom = new DomDocument('<root />');

This will create a document with like the following:

<?xml version="1.0"?>

If you want to set the encoding, you can do the following:

$dom = new DomDocument(
    '<?xml version="1.0" encoding="utf-8"?><root />'

This will create the following document:

<?xml version="1.0" encoding="utf-8"?>


Site Timeline