douyan3478 2014-04-27 09:08
浏览 88
已采纳

解析NWS XML数据 - 上限:地理编码

I followed the info here:

Parse XML namespaces with php SimpleXML

And that works for everything except the information contained in the "cap:geocode" and "cap:parameter" entries.

$geocode = $entry->children('cap',true)->geocode;

returns an empty value.

Any ideas on how to get at the data inside of the cap:geocode and cap:parameter entries?

<cap:geocode>
    <valueName>FIPS6</valueName>
    <value>048017 048079</value>
    <valueName>UGC</valueName>
    <value>TXZ027 TXZ033</value>
</cap:geocode>

I need to read the ValueName/Value pairs.

  • 写回答

2条回答 默认 最新

  • doushao5047 2014-05-12 01:51
    关注

    I used this example here: https://github.com/tylerlane/php.news-leader.com/blob/master/weather/alerts.php

    And simplified it for my purposes to get this (echo.php just prints the data out):

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)