php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dgrimes at scvl dot com
New email:
PHP Version: OS:

 

 [2007-06-19 17:49 UTC] dgrimes at scvl dot com
Description:
------------
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" ?>
<note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
</note>

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 php.net xml examples. Everyghing works OK in php4 but not php5.

Here is the test program:

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

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

function endElement($parser, $name) 
{
    global $depth;
    $depth[$parser]--;
}

$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",
                    xml_error_string(xml_get_error_code($xml_parser)),
                    xml_get_current_line_number($xml_parser)));
    }
}
xml_parser_free($xml_parser);
?> 


Expected result:
----------------
NOTE
  TO
  FROM
  HEADING
  BODY


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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-20 09:26 UTC] rrichards@php.net
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.

Thanks,
Dean
 [2007-06-25 18:02 UTC] tony2001@php.net
Yes, the problem is definitely related to libxml2, not PHP.
 [2007-06-25 18:03 UTC] tony2001@php.net
.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 29 03:03:33 2021 UTC