What am i doing wrong with simplexml_load_file?

so i’ve used simplexml_load_file with a xml url source and it works fine. But i’ve now tried it with a data source from a different source and it doesn’t want to display anything. I’ve tried numerous changes and configurations.

The data source is the environment agencies bathing water data http://environment.data.gov.uk/doc/bathing-water.xml?eubwidNotation=ukk2302-35300

this is a variation of the code i’ve been trying

$xml=simplexml_load_file("http://environment.data.gov.uk/doc/bathing-water/ukc2102-03600.xml") or die("Error: Cannot create object");
echo '<div id="heading">';
echo $xml->items[0]->item['href']. "<br>";
echo '</div>';

any help would be appreciated. probably something really simple but i can’t see it

Hi Noppy,

The problem is that you’re trying to access the items collection, which exists in the XML document that you linked to, but not in the one you’re opening in your PHP code.

omg! why does that work now. I’m pretty sure i tried both URLs (both return xml data from the same source) and various calls to ‘results->’ and about 10 different configurations to get it to work.

thanks for pointing that out, seems to be doing what i expected now. Now i just have to actually point it to the info i need.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.