Connecting Tech Pros Worldwide Forums | Help | Site Map

XML DOM Setup with PHP

fionathomson
Guest
 
Posts: n/a
#1: Nov 9 '05
Hi,


I am using PHP version 4.4.0.0 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 =
"C:/php/extensions"
2. Loaded the xmldom module by uncommenting the line in php.ini
extension=php_domxml.dll
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


domxml
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?


Thanks,
Fiona




Janwillem Borleffs
Guest
 
Posts: n/a
#2: Nov 9 '05

re: XML DOM Setup with PHP


fionathomson wrote:[color=blue]
> PHP Warning: domdocument() expects at least 1 parameter, 0 given in
> F:\web\popup\test.php on line 11
>[/color]

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

$dom = new DOMDocument("1.0");


JW



fionathomson
Guest
 
Posts: n/a
#3: Nov 10 '05

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:

<?php

$doc = new DOMDocument("1.0");
?>

Can you suggest anything else to try?

Janwillem Borleffs
Guest
 
Posts: n/a
#4: Nov 10 '05

re: XML DOM Setup with PHP


fionathomson wrote:[color=blue]
> 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
>[/color]

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"?>
<root/>

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"?>
<root/>


HTH;
JW



Closed Thread