Error in Parsing XML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Error in Parsing XML

Post by PHPForever »

Hi,
This should be a simple one - my php script is trying to create an XML document.
However when I open the script on the browsert I get an error.
Below is thescript and the error.
Thanks.

SCRIPT

<?php

//Creates XML string and XML document using the DOM
$dom = new DomDocument('1.0');

//add root - <books>
$books = $dom->appendChild($dom->createElement('books'));

//add <book> element to <books>
$book = $books->appendChild($dom->createElement('book'));

//add <title> element to <book>
$title = $book->appendChild($dom->createElement('title'));

//add <title> text node element to <title>
$title->appendChild(
$dom->createTextNode('Great American Novel'));

//generate xml
$dom->formatOutput = true; // set the formatOutput attribute of
// domDocument to true
// save XML as string or file
$test1 = $dom->saveXML(); // put string in test1
$dom->save('C:/test1.xml'); // save as file
?>


ERROR:



Warning: domdocument::domdocument() [domdocument.domdocument]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\phpxml.php on line 4

Warning: domdocument::domdocument() [domdocument.domdocument]: 1.0 in C:\xampp\htdocs\phpxml.php on line 4

Warning: domdocument::domdocument() [domdocument.domdocument]: ^ in C:\xampp\htdocs\phpxml.php on line 4

Fatal error: Call to undefined method domdocument::appendChild() in C:\xampp\htdocs\phpxml.php on line 7

Could someone guide on whats wrong here ?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Error in Parsing XML

Post by Maugrim_The_Reaper »

What's your PHP version? I tested the code and it works fine here...
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Re: Error in Parsing XML

Post by PHPForever »

PHP 5

I checked to see if the httpd.conf file under XAMPP Apache had the following lines

# For PHP 5 do something like this:
#LoadModule php5_module "c:/php/php5apache2.dll"
LoadModule php5_module "C:\Users\Suraj\Softwares\php-5.2.6-Win32\php5apache2_2.dll"
AddType application/x-httpd-php .php

# configure the path to php.ini
#PHPIniDir "C:/Windows"

It didn't - so I added it, and restarted Apache but I still got the same errors

ERROR:

Warning: domdocument::domdocument() [domdocument.domdocument]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\phpxml.php on line 5

Warning: domdocument::domdocument() [domdocument.domdocument]: 1.0 in C:\xampp\htdocs\phpxml.php on line 5

Warning: domdocument::domdocument() [domdocument.domdocument]: ^ in C:\xampp\htdocs\phpxml.php on line 5

Fatal error: Call to undefined method domdocument::appendChild() in C:\xampp\htdocs\phpxml.php on line 8
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Re: Error in Parsing XML

Post by PHPForever »

I even checked the php switch from the home page of XAMPP.
It has version 5.2.6 of PHP.

Also I was checking through some forums, they have mentioned that the line

extension=php_domxml.dll

should be commented in the php.ini file. So I've commented this in php.ini and php5.ini that comes with XAMPP..

Refreshed XAMPP and restarted Apache MYsql.

But still I get the same errors.
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Re: Error in Parsing XML

Post by PHPForever »

Can someone please guide here ? I am at a dead end.
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Re: Error in Parsing XML

Post by PHPForever »

The dom xml also seems enabled for xampp.
This is the php info



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


domxml
DOM/XML enabled
DOM/XML API Version 20030407
Extension Version 1.0.0
libxml Version 20632
HTML Support enabled
XPath Support enabled
XPointer Support enabled


Do you have the same version ?
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Re: Error in Parsing XML

Post by PHPForever »

It finally worked !!

Apparenly the php_domxml.dll extension had to be commented in the php.ini file under apache/bin.

Got the info from this link http://www.gotgtek.net/forum/index.php?topic=2200.0

Thanks for the help Maugrim
Post Reply