PHP SimpleXML Namespace Problem

前端 未结 1 971
执念已碎
执念已碎 2020-11-27 22:53

I\'m trying to get the entry->id and entry->cap:parameter->value for every entry in the RSS feed.... below is the code I\'m using. It is displaying the id correctly however

1条回答
  •  佛祖请我去吃肉
    2020-11-27 23:53

    The element is not in the same namespace as :

    
        VTEC
        /O.CON.KMPX.FL.W.0012.000000T0000Z-110517T1800Z/
    
    

    So you have to call children() again.

    Code (demo)

    $feed = simplexml_load_file('http://alerts.weather.gov/cap/us.php?x=1');
    foreach ($feed->entry as $entry){
        printf(
            "ID: %s\nVTEC: %s\n
    ", $entry->id, $entry->children('cap', true)->parameter->children()->value ); }

    0 讨论(0)
提交回复
热议问题