Page 1 of 1

Newbie to XML getting error message

PostPosted: 23. June 2011 11:32
by Dust
Hi all

Hope someone can help me. I'm just dipping my toe into working with XML documents and I'm having a problem. So far, I've managed to read documents without a problem but I'm now taking the next step of adding to and creating new XML sheets. I'm having a look at this article here:

http://www.devshed.com/c/a/PHP/A-Quick-Overview-of-the-XML-DOM-Extension-in-PHP-5/1/

..and trying to run this piece of code from XAMPP:

Code: Select all
$dom=new DOMDocument('1.0','iso-8859-1');
$element=$dom->createElement('testnode','This is the root element of the new DOM document');
// insert the new element as root (child of the document)
$dom->appendChild($element);
// tell the browser the output is XML via the 'Content-Type' HTTP header
header('Content-Type: text/xml');
// display DOM document
echo $dom->saveXML();


But's it's coming up with this error message:

This page contains the following errors:

error on line 1 at column 60: Space required after the Public Identifier
Below is a rendering of the page up to the first error.


Can anyone tell me, is it XAMPP causing this error, or a problem with the code itself?

Thanks

Re: Newbie to XML getting error message

PostPosted: 23. June 2011 14:38
by BigWetDog
Dust,
First off, do you know your php configuration is good? I had no trouble running your example.
Second, just at a glance that error doesn't seem right. That is to say it doesn't appear to be related to your code. Is there anything else in the file with this?
Just googling, that appears to be a common error thrown by the simplexml_load_string method. Are you trying to read the xml output by your code into another object? Check the php documentation.