|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-06-20 09:26 UTC] rrichards@php.net
[2007-06-21 20:57 UTC] dgrimes at scvl dot com
[2007-06-25 18:02 UTC] tony2001@php.net
[2007-06-25 18:03 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 05:00:01 2025 UTC |
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.