Xpath get bits of array

Hi,
my brain has stopped working and i can’t for the life of me work this out. I’m trying to get data from an xml feed and pull out certain pieces.
So far i have this

$xmlinfo = simplexml_load_file("http://environment.data.gov.uk/doc/bathing-water/ukd4305-43550.xml");

$resulta = $xmlinfo->xpath("primaryTopic/latestRiskPrediction ");

print_r($resulta);

which outputs …
http://test.goodbeachguide.co.uk/wid.php

i can’t work out how to get the separate parts from that array. The way i’ve done it with other feeds isn’t working and i don’t know what i am going wrong.
I’ve tried stuff like

echo $resulta['expiresAt'];

or

echo $resulta[0]['expiresAt'];

any pointers on what i am doing wrong or what this type of array is so i can at least google it.

thanks

echo $resulta[0]->expiresAt;, although that would be easier to tell if we knew the XML structure of the selected part.

hey thanks i’ll have a play and see what happens

the data comes from here http://environment.data.gov.uk/doc/bathing-water/ukd4305-43550.xml

thanks

as reference, the selected bit from the XML:

<latestRiskPrediction href="http://environment.data.gov.uk/data/bathing-water-quality/stp-risk-prediction/point/43550/date/20150506-083519">
    <expiresAt datatype="dateTime">2015-05-07T08:29:00</expiresAt>
    <riskLevel href="http://environment.data.gov.uk/def/bwq-stp/increased">
        <name lang="en">increased</name>
    </riskLevel>
</latestRiskPrediction>

thanks. Sorry i should have cut the bit rather than get you to have to find it.

So i need to get the first href to use in a sub lookup to get the cause of the warning. So this works to get the url

echo $resulta[0]->attributes();

But is that the correct way to do it? If so i can then use it for the next part.

thanks

I’d go for $resulta[0]['href'] (as described in the Manual).

thanks, could have sworn i’d tried that. Doh!

all working now. That’s been incredibly helpful thank you

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