I have the xml file below (named as test.xml):
<?xml version="1.0" encoding="UTF-8" ?>
<films>
<film>
<title rating="7.8">The Three Amigos</title>
<category>comedy</category>
<director>John Landis</director>
<country>United States</country>
</film>
<film>
<title rating="9.1">Brief Encounter</title>
<category>romance</category>
<director>David Lean</director>
<country>Great Britain</country>
</film>
</films>
Now, when running the below php code, I'm getting an error:
"XML Parsing Error: junk after document element Warning: DOMDocument::load() [domdocument.load0]: I/O warning : failed to load external entity "" in line 5".
I have no idea why the error is thrown. Please help.
<?php
$file = 'test.xml';
$doc = new DOMDocument();
$doc->load($file);
header("Content-Type: text/xml");
print $doc->saveXML();
?>
Maybe some hidden or crunched characters around line 5?
Your script is running fine on my PHP 5.3.
You can try strip your XML to the smallest possible like:
<films></films>
Then add your original file element by element.