douxianxing5712 2012-04-30 16:08
浏览 48
已采纳

获取与另一个节点匹配的xml节点

Hi I am trying to get node that contains the text 116.. but what I am trying is not working. Any help would be greatly appreciated!!

XML (codes.xml):

<codes>
<condition>
<code>116</code>
<description>Moderate or heavy snow in area with thunder</description>
<day_icon>wsymbol_0012_heavy_snow_showers</day_icon>
<night_icon>wsymbol_0028_heavy_snow_showers_night</night_icon>
</condition>
<condition>
<code>392</code>
<description>Patchy light snow in area with thunder</description>
<day_icon>wsymbol_0016_thundery_showers</day_icon>
<night_icon>wsymbol_0032_thundery_showers_night</night_icon>
</condition>
</codes>

My PHP CODE TO CALL:

$codes = simplexml_load_file('xml/codes.xml');

foreach($codes->codes->condition AS $match){
    if($match->code == "116")
    {echo $match->description;}
    };
  • 写回答

2条回答 默认 最新

  • doujiyun0041 2012-04-30 16:13
    关注

    $codes is the root node, not $codes->codes

    foreach($codes->condition AS $match)
    {
        if($match->code == "116")
        {
            echo $match->description;
        }
    };
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,