$xmlstr = simplexml_load_file('newstouload.xml');
$xml = new SimpleXMLElement($xmlstr);
foreach ($xml->movie[0]->rating as $rating) {
switch((string) $rating['type']) { // Get attributes as element indices
case 'thumbs':
echo $rating, ' thumbs up';
break;
case 'stars':
echo $rating, ' stars';
break;
}
}
My error is
Warning: simplexml_load_file() [function.simplexml-load-file]: newstouload.xml:2: parser error : XML declaration allowed only at the start of the document in /home/rlnz/public_html/application/publishnews.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: <?xml version="1.0" encoding="ISO-8859-1"?> in /home/rlnz/public_html/application/publishnews.php on line 3
Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in /home/rlnz/public_html/application/publishnews.php on line 3
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/rlnz/public_html/application/publishnews.php:5 Stack trace: #0 /home/rlnz/public_html/application/publishnews.php(5): SimpleXMLElement->__construct('') #1 {main} thrown in /home/rlnz/public_html/application/publishnews.php on line 5