I have just started experimenting with php & xml.
Followed the samples came with the DOM API section on this site. I was able to load the book.xml from the file system with the code like this.
- Code: Select all
<?php
$doc = DOMDocument::load('book.xml');
echo $doc->saveXML();
$doc = new DOMDocument();
$doc->load('book.xml');
echo $doc->saveXML();
?>
However, when I want to load from a string, like below.
- Code: Select all
<?php
$doc = DOMDocument::loadXML('<root><node/></root>');
echo $doc->saveXML();
$doc = new DOMDocument();
$doc->loadXML('<root><node/></root>');
echo $doc->saveXML();
?>
I got this error.
Only one top level element is allowed in an XML document. Error processing resource 'http://localhost/contest/loadXML.php'. Line 4, Position 2
<root><node/></root>
-^
I am using xampp for Windows 1.5.1. Anyone knows why? Please help. Many thanks.