php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53694 SimpleXMLElement does not read XML declaration line.
Submitted: 2011-01-08 10:04 UTC Modified: 2011-01-08 12:15 UTC
From: jamone_95134 at yahoo dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.3.5 OS: Windows XP
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jamone_95134 at yahoo dot com
New email:
PHP Version: OS:

 

 [2011-01-08 10:04 UTC] jamone_95134 at yahoo dot com
Description:
------------
---
From manual page: http://www.php.net/simplexml.examples-basic
---
When I run the first example I get the following errors:

$ php test1.php

Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : XML 
declaration allowed only at the start of th
e document in D:\php_src\XML\test1.php on line 4

Warning: SimpleXMLElement::__construct():       <?xml version="1.0" 
encoding="utf-8"?> in D:\php_src\XML\test1.php on li
ne 4

Warning: SimpleXMLElement::__construct():            ^ in 
D:\php_src\XML\test1.php on line 4

Fatal error: Uncaught exception 'Exception' with message 'String could not be 
parsed as XML' in D:\php_src\XML\test1.php
:4
Stack trace:
#0 D:\php_src\XML\test1.php(4): SimpleXMLElement->__construct('?<?xml 
version=...')
#1 {main}
  thrown in D:\php_src\XML\test1.php on line 4


If I remove the <?xml version="1.0" encoding="utf-8"?> line from the example.php 
file it runs ok.

So how do we handle the declaration line for xml files with SimpleXMLElement?

Test script:
---------------
Just running example 2 from http://www.php.net/manual/en/simplexml.examples-basic.php

Expected result:
----------------
Expected result:

So, this language. It's like, a programming language. Or is it a
scripting language? All is revealed in this thrilling horror spoof
of a documentary.

Actual result:
--------------
$ php test1.php

Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : XML 
declaration allowed only at the start of th
e document in D:\php_src\XML\test1.php on line 4

Warning: SimpleXMLElement::__construct():       <?xml version="1.0" 
encoding="utf-8"?> in D:\php_src\XML\test1.php on li
ne 4

Warning: SimpleXMLElement::__construct():            ^ in 
D:\php_src\XML\test1.php on line 4

Fatal error: Uncaught exception 'Exception' with message 'String could not be 
parsed as XML' in D:\php_src\XML\test1.php
:4
Stack trace:
#0 D:\php_src\XML\test1.php(4): SimpleXMLElement->__construct('?<?xml 
version=...')
#1 {main}
  thrown in D:\php_src\XML\test1.php on line 4


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-08 12:15 UTC] rrichards@php.net
-Status: Open +Status: Bogus
 [2011-01-08 12:15 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

invalid characters before start of declaration.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC