timcbest Posted December 20, 2006 Share Posted December 20, 2006 I think my ajax is working fine but the XML produced by PHP 5.2.0 is coming back with this error:XML Parsing Error: xml declaration not at start of external entityLocation: http://mysite/getcounty.php?state=MSLine Number 1, Column 2: <?xml version="1.0" encoding="UTF-8"?>-^This is the function that creates the XML: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(); }In firebug the server response is coming back: <?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>Which is correct. How do I eliminate the '-^'? Is that an extra line? THis started happening after I upgraded from 5.1.3 to 5.2.0. Thanks!Tim Quote Link to comment https://forums.phpfreaks.com/topic/31393-dom-problem-on-php-side/ Share on other sites More sharing options...
ober Posted December 20, 2006 Share Posted December 20, 2006 Could be an issue with the parser in 5.2. Have you submitted a bug and can you downgrade to 5.1.3? Quote Link to comment https://forums.phpfreaks.com/topic/31393-dom-problem-on-php-side/#findComment-145335 Share on other sites More sharing options...
timcbest Posted December 20, 2006 Author Share Posted December 20, 2006 haven't reported a bug yet. Will do so... I think I am going to rewrite and use JSON for now - can't back out to 5.1.3 Quote Link to comment https://forums.phpfreaks.com/topic/31393-dom-problem-on-php-side/#findComment-145359 Share on other sites More sharing options...
448191 Posted December 20, 2006 Share Posted December 20, 2006 There is a space before your XML declaration.Not sure what is causing it though. I was meaning to upgrade to 5.2, so I decided to test this out.I found no problems on 5.1.4 nor 5.2..[code]<?phperror_reporting(E_ALL | E_STRICT);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(); }formulateResponse(array(array('county'=>'Adams')));?>[/code][code]<?xml version="1.0" encoding="UTF-8"?><response> <county>Adams</county></response>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31393-dom-problem-on-php-side/#findComment-145372 Share on other sites More sharing options...
448191 Posted December 20, 2006 Share Posted December 20, 2006 I can even get it to validate:[code]<?phperror_reporting(E_ALL | E_STRICT);function formulateResponse($info){ $domImpl = new DomImplementation; $docType = $domImpl->createDocumentType('response','','response.dtd'); $dom = $domImpl->createDocument('', 'response', $docType); $dom->encoding = 'UTF-8'; $dom->formatOutput = true; foreach($info as $index => $county_array){ $county = $dom->createElement('county'); $county = $dom->documentElement->appendChild($county); $name = $dom->createTextNode($county_array['county']); $name = $county->appendChild($name); } header('Content-Type: text/xml'); $dom->validate(); echo $dom->saveXML();}formulateResponse(array(array('county'=>'Adams')));?>[/code][i]response.dtd[/i][code]<!ELEMENT response (county+)><!ELEMENT county (#PCDATA)>[/code]Output:[code]<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE response SYSTEM "response.dtd"><response> <county>Adams</county></response>[/code]No probs whatsoever...How about your JS? Quote Link to comment https://forums.phpfreaks.com/topic/31393-dom-problem-on-php-side/#findComment-145381 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.