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.
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力
  • ¥15 c语言题目:成绩管理系统