simplexml_load_file : XML declaration allowed only at the start of the document

attahelessy

New Member
I want to parse some XML document in PHP with Simple XML.I use simplexml_load_file and I got this error : \[code\]Warning: simplexml_load_file(): [myfile] parser error : XML declaration allowed only at the start of the document in /www/[...]/myphpfile.php on line 7\[/code\]I have searched on google, and the problem seems to be that there are some wwhitespaces before tags in XML document. I checked, there is no whitespace before.Here is my code : \[code\]libxml_use_internal_errors(true);$sxml=simplexml_load_file($xml);if ($sxml) { echo '<h2>'.$xml.'</h2>'; echo '<p>author: <textarea>'; foreach($sxml->author as $author) { if($author!=$strXML) echo $author.'\n'; } echo '</textarea></p>';}else { echo "Failed loading XML\n"; foreach(libxml_get_errors() as $error) echo "\t", $error->message;\[/code\]}edit : error is \[code\]Failed loading XML XML declaration allowed only at the start of the document Extra content at the end of the document\[/code\]first tag of the xml document \[code\]<?xml version="1.0" encoding="UTF-8"?>\[/code\]
 
Back
Top