|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41740 XML Declaration Error
Submitted: 2007-06-19 17:49 UTC Modified: 2007-06-25 18:03 UTC
From: dgrimes at scvl dot com Assigned:
Status: Not a bug Package: *XML functions
PHP Version: 5.2.3 OS: Compaq Tru64
Private report: No CVE-ID: None
 [2007-06-19 17:49 UTC] dgrimes at scvl dot com
I'm getting the following error:

XML error: XML declaration not finished at line 1

Here is the xml code:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
        <body>Don't forget me this weekend!</body>

However, if I remove line one completely the code works but I can't have any reference to <?xml .... ?>.

Reproduce code:
I took this code from the xml examples. Everyghing works OK in php4 but not php5.

Here is the test program:

$file = "test.xml";
$depth = array();

function startElement($parser, $name, $attrs) 
    global $depth;
    for ($i = 0; $i < $depth[$parser]; $i++) {
        echo "  ";
    echo "$name\n";

function endElement($parser, $name) 
    global $depth;

$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
    die("could not open XML input");

while ($data = fread($fp, 4096)) {
    if (!xml_parse($xml_parser, $data, feof($fp))) {
        die(sprintf("XML error: %s at line %d",

Expected result:

This was run with the above code without the <?xml ... ?> line.

Actual result:
XML error: XML declaration not finished at line 1

Run with the same code with the <?xml ... ?> line.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-20 09:26 UTC]
Try updating libxml2. I cant reproduce this (testing with 2.6.26 and higher).
 [2007-06-21 20:57 UTC] dgrimes at scvl dot com
I loaded latest of both libxml2 (2.6.29) and libxslt (1.1.20) and I still have the same problem. Should I be contacting the developers of those libraries rather than you? If you're thinking the problem is with libxml2 then perhaps the problem is not with PHP at all.

 [2007-06-25 18:02 UTC]
Yes, the problem is definitely related to libxml2, not PHP.
 [2007-06-25 18:03 UTC]
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 01:01:31 2024 UTC