Cannot use DOMDocument class for PHP even though everything seems to be installed on server

Hello,

I am reading and going through the examples in the book "Beginning Ajax" by Wrox.

Pretty quickly I ran into trouble. I was unable to use the DOMDocument class in PHP.

The error I am getting is "Fatal error: Class 'DOMDocument' not found in /var/www/html/dev/ch3/test.php"

After looking around the web, I found that usually it was because the PHP-XML was not installed on the server, so I installed that. Still no go.

I decided to try a more basic example from PHP.net (shown in the snippet) and also available here: http://us2.php.net/manual/en/function.dom-domdocument-savexml.php but got the same error

Here is the URL to this code on the server:http://www.mvtimes.com/dev/ch3/test.php

We have PHP 5.1.6 installed with XML functionality enabled: http://www.mvtimes.com/info.php

Any insight or help would be greatly appreciated.

Thank you,
Rick
<?php
$doc = new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput = true;
 
$root = $doc->createElement('book');
$root = $doc->appendChild($root);
 
$title = $doc->createElement('title');
$title = $root->appendChild($title);
 
$text = $doc->createTextNode('This is the title');
$text = $title->appendChild($text);
 
echo "Saving all the document:\n";
echo $doc->saveXML() . "\n";
 
echo "Saving only the title part:\n";
echo $doc->saveXML($title);
?>

Open in new window

EdeneyeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hernst42Commented:
You have compiled dom, but not loaded it into php. In your info you must see something like:

dom
DOM/XML       enabled
DOM/XML API Version       20031129
libxml Version       2.6.27
HTML Support       enabled
XPath Support       enabled
XPointer Support       enabled
Schema Support       enabled
RelaxNG Support       enabled

Edit your php.ini and add a line like:
extension=dom.so
(look in /usr/lib/php/modules for the correct name)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EdeneyeAuthor Commented:
Thank you. That was exactly it.
0
EdeneyeAuthor Commented:
hernst42 got it exactly right, thanks.

For others that may come across this, the site I am working on is a virtual site on the server.
The dom.so extension was in the server level /usr/lib/php/modules but not in the site's correspondin folder.

I didn't really want to fiddle with it too much, so I assumed that since I had a separate modules folder for the site and a separate php.ini for the site that I should copy the dom.so to the site's module folder and edit that site's php.ini.

So I copied /usr/lib/php/modules/dom.so to /home/virtual/site1/fst/usr/lib/php/modules and added the line
extension=dom.so to /home/virtual/site1/fst/etc/php.ini

I restarted apache and everything worked as expected.

Thanks again!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.