PHP SimpleXML Namespace Problem

The <value> element is not in the same namespace as <cap:parameter>:

<cap:parameter>
    <valueName>VTEC</valueName>
    <value>/O.CON.KMPX.FL.W.0012.000000T0000Z-110517T1800Z/</value>
</cap:parameter>

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<hr>",
        $entry->id,
        $entry->children('cap', true)->parameter->children()->value
    );
}

Leave a Comment