#39909 [NEW]: XML Parsing Error: xml declaration not at start of external entity
| From: | timcbest at gmail dot com | Date: | Wed, 20 Dec 2006 19:27:13 +0000 |
| Subject: | #39909 [NEW]: XML Parsing Error: xml declaration not at start of external entity | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-106682@lists.php.net to get a copy of this message | ||
From: timcbest at gmail dot com
Operating system: FreeBSD
PHP version: 5.2.0
PHP Bug Type: DOM XML related
Bug description: XML Parsing Error: xml declaration not at start of external entity
Description:
------------
When generating XML from DOMDocument I get this error:
Error:
XML Parsing Error: xml declaration not at start of external
entity
Location: http://test.mysite.com/getcounty.php?state=MS
Line Number 1, Column 2: <?xml version="1.0" encoding="UTF-8"?
>
-^
Reproduce code:
---------------
function formulateResponse($info){
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;
$root = $dom->createElement('response');
$root = $dom->appendChild($root);
foreach($info as $index => $county_array){
$county = $dom->createElement('county');
$county = $root->appendChild($county);
$name = $dom->createTextNode($county_array['county']);
$name = $county->appendChild($name);
}
header('Content-Type: text/xml');
echo $dom->saveXML();
}
Expected result:
----------------
I expect the browser to be able to parse the XML below.
This is the XML generated by the above function. Whether I
call it from an Ajax call or directly in the browser
(Firefox 1.5.0.8 or Safari 2.0.4) the error is generated as
specified in the description box above.
<?xml version="1.0" encoding="UTF-8"?>
<response>
<county>Adams</county>
<county>Alcorn</county>
<county>Amite</county>
<county>Attala</county>
<county>Benton</county>
<county>Bolivar</county>
<county>Calhoun</county>
<county>Carroll</county>
<county>Chickasaw</county>
<county>Choctaw</county>
<county>Claiborne</county>
<county>Clarke</county>
<county>Clay</county>
<county>Coahoma</county>
<county>Copiah</county>
<county>Covington</county>
<county>De Soto</county>
<county>Forrest</county>
<county>Franklin</county>
<county>George</county>
<county>Greene</county>
<county>Grenada</county>
<county>Hancock</county>
<county>Harrison</county>
<county>Hinds</county>
<county>Holmes</county>
<county>Humphreys</county>
<county>Issaquena</county>
<county>Itawamba</county>
<county>Jackson</county>
<county>Jasper</county>
<county>Jefferson</county>
<county>Jefferson Davis</county>
<county>Jones</county>
<county>Kemper</county>
<county>Lafayette</county>
<county>Lamar</county>
<county>Lauderdale</county>
<county>Lawrence</county>
<county>Leake</county>
<county>Lee</county>
<county>Leflore</county>
<county>Lincoln</county>
<county>Lowndes</county>
<county>Madison</county>
<county>Marion</county>
<county>Marshall</county>
<county>Monroe</county>
<county>Montgomery</county>
<county>Neshoba</county>
<county>Newton</county>
<county>Noxubee</county>
<county>Oktibbeha</county>
<county>Panola</county>
<county>Pearl River</county>
<county>Perry</county>
<county>Pike</county>
<county>Pontotoc</county>
<county>Prentiss</county>
<county>Quitman</county>
<county>Rankin</county>
<county>Scott</county>
<county>Sharkey</county>
<county>Simpson</county>
<county>Smith</county>
<county>Stone</county>
<county>Sunflower</county>
<county>Tallahatchie</county>
<county>Tate</county>
<county>Tippah</county>
<county>Tishomingo</county>
<county>Tunica</county>
<county>Union</county>
<county>Walthall</county>
<county>Warren</county>
<county>Washington</county>
<county>Wayne</county>
<county>Webster</county>
<county>Wilkinson</county>
<county>Winston</county>
<county>Yalobusha</county>
<county>Yazoo</county>
<county>Statewide</county>
</response>
Actual result:
--------------
Error:
XML Parsing Error: xml declaration not at start of external
entity
Location: http://test.mysite.com/getcounty.php?state=MS
Line Number 1, Column 2: <?xml version="1.0" encoding="UTF-8"?
>
-^
--
Edit bug report at http://bugs.php.net/?id=39909&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39909&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39909&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39909&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39909&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=39909&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39909&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39909&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39909&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39909&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39909&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=39909&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=39909&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39909&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39909&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39909&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39909&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39909&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39909&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39909&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39909&r=mysqlcfg