我在这里使用了这个例子:https ://github.com/tylerlane/php.news-leader.com/blob/master/weather/alerts.php
并出于我的目的对其进行了简化以获取此信息(echo.php 只是将数据打印出来):
$dataFileName = "wx/CAP.xml";
//load the feed
$capXML = simplexml_load_file($dataFileName);
//how many items
$itemsTotal = count($capXML->entry);
if(count($itemsTotal)):
$capXML->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom');
$result = $capXML->xpath("//prefix:entry");
foreach($result as $capXML):
$dc = $capXML->children('urn:oasis:names:tc:emergency:cap:1.1');
$event = $dc->event;
$effective = $dc->effective;
$expires = $dc->expires;
$status = $dc->status;
$msgType = $dc->msgType;
$category = $dc->category;
$urgency = $dc->urgency;
$severity = $dc->severity;
$certainty = $dc->certainty;
$areadesc = $dc->areaDesc;
$geopolygon = $dc->polygon;
//get the children of the geocode element
$geocodechildren = $dc->geocode->children();
//only interested in FIPS6 for now
//no guarantee that FIPS6 will be the first child so we have to deal with that
if($geocodechildren->valueName == "FIPS6"){
//isolate all the FIPS codes
$fips = explode( " ", $geocodechildren->value );
} else {
//hide everything else so we don't fail
$fips = Array();
}
//get the VTEC
$parameter_children = $dc->parameter->children();
if($parameter_children->valueName == "VTEC"){
//isolate all VTEC codes
$vtec = explode( ".", $parameter_children->value );
} else {
//hide anything else that may show up
$vtec = Array();
}
include('echo.php');
print_r($fips);
echo "<br/>";
print_r($vtec);
echo "<hr/>";
endforeach;
endif;