开发者

reading a XML feed with '-' in some of the element names

开发者 https://www.devze.com 2023-03-03 16:36 出处:网络
I am trying to read an xml feed that has \'-\' in the element names. The feed can be found here. http://forecast.weather.gov/MapClick.php?lat=42.19774&lon=-121.81797&FcstType=dwml

I am trying to read an xml feed that has '-' in the element names. The feed can be found here.

http://forecast.weather.gov/MapClick.php?lat=42.19774&lon=-121.81797&FcstType=dwml

I am new to php, so I am likely over looking something basic. I am using SimpleXML to read the feed. Here is some basic code that I am using to figure out my problem. I read the wordedForecast and min tempature with no problems. When I try to read the conditions-icon the php does not work(it is the part that I commented out at the bottom)

<?php 
$feed_url = 'http://forecast.weather.gov/MapClick.php?lat=42.19774&lon=-121.81797&FcstType=dwml';
$ch = curl_init($feed_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

if (!empty($result))
{
$xml = new SimpleXMLElement($result);
print "<br> Discription\n";
$wordedForecast = $xml->data->parameters->wordedForecast->text;
foreach ($wordedForecast as  $value)
{
    print "<br> $value\n";
}
print "<br> Min Tempature\n";
$Tempature = $xml->data->parameters->temperature->value;
foreach ($Tempature as  $value)
{
    print "<br> $value\n";
}
    print"<br>conditions Icon link\n";
//This is one of the elements that I am stumped on how to read.
/*      $conditions= $xml->data->parameters->conditions-icon->icon-link;
foreach ($conditions as  $value)
{
    print "<br> $value\n";
}
*/  
}
?>

I am sure the answer to this is simple, but I have开发者_StackOverflow社区 run out of ideas on how to go about it. I have the same problem with the <time-layout>,<probability-of-precipitation>, and <weather-conditions> elements.

Thanks for any answers or ideas on how to get it working.


try $xml->data->parameters->{'conditions-icon'}->{'icon-link'}

0

精彩评论

暂无评论...
验证码 换一张
取 消