Error in Parsing XML
Posted: Thu Sep 18, 2008 11:11 am
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 ?
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 ?