doushijia5684 2015-06-23 19:06
浏览 25
已采纳

什么都不做 - simpleXML PHP

It's not doing anything when I run it... I suppose It should write something like:

O nás Produkty

Here is the PHP code (line 50 because it's inside HTML code):

<?php
$menu=simplexml_load_file('menu.xml') or die('Cannot read menu!');
foreach((array) $menu->menu_items->item as $HTMLTAG)
{
echo $HTMLTAG;
} 
?>

And here is a part of the XML:

<?xml version="1.0" encoding="utf-8"?>
<menu_items>
<item link_url="#" active="on">O nás
<subitem link_url="/about" active="on">O nás</subitem>
<subitem link_url="/about/reference" active="on">Reference</subitem>
<subitem link_url="/about/contact" active="on">Kontakty</subitem>
</item>
<item link_url="#" active="on">Produkty
<subitem link_url="/HeatMatrix" active="on">O nás
<under_subitem link_url="/HeatMatrix/LUVO">Předehřívač vzduchu LUVO</under_subitem>
<under_subitem link_url="/HeatMatrix/HV">Hybridní výměníky</under_subitem>
<under_subitem link_url="/HeatMatrix/KP">Výměníky kapalina-plyn</under_subitem>
<under_subitem link_url="/HeatMatrix/VCS">Vestavěný čistící systém</under_subitem></subitem>
<subitem link_url="/OCR" active="off">OCR systémy</subitem>
<subitem link_url="/LDR" active="off">Točivé redukce</subitem>
</item>
</menu_items>

Don't you know what should I do about it?

  • 写回答

1条回答 默认 最新

  • dsf11t5u1651 2015-06-23 19:29
    关注

    The ->menu_items also does not need to be there, since it is the root node of the XML document. This worked for me:

    foreach($menu->item as $HTMLTAG)
    {
        echo $HTMLTAG; //I used print_r here actually, which was nicer.
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划