我有 XML 文件。这是电影放映时间,我尝试解析。
<?xml version="1.0" encoding="UTF-8"?> <billboard>
<genres>
<shows>
<show id="160576" film_id="5710" cinema_id="89" hall_id="241">
<begin>2012-11-15</begin>
<end>2012-11-18</end>
<times>
<time time="12:30:00">
<prices>30, 55</prices>
<note><![CDATA[]]></note>
</time>
<time time="14:45:00">
<prices>30, 55</prices>
<note><![CDATA[]]></note>
</time>
<time time="17:00:00">
<prices>30, 55</prices>
<note><![CDATA[]]></note>
</time>
<time time="23:45:00">
<prices>30, 55</prices>
<note><![CDATA[]]></note>
</time>
</times>
</show>
我解析了我的 XML 并回显内容。但我无法回显“时间”和“价格”。插入代码后“//回显时间和价格//”脚本不起作用(白屏)。请帮助。PS对不起我的英语。
$xmlstr = file_get_contents('test.xml');
$x = new SimpleXMLElement($xmlstr);
$id_f = 89;
$cinema_id = "//show[@cinema_id=".$id_f."]";
$cinema=$x->xpath($cinema_id);
///////////////////////start/////////////////////////////////////////////
foreach($cinema as $cinema)
{
///////////string///////////////////
$begin_m = $cinema[0]->begin;
$end_m = $cinema[0]->end;
$film_id_m = $cinema[0]['film_id'];
/////////echo//////////////////////
echo "<b>Begin: </b>".$begin_m."<br>";
echo "<b>End: </b>".$end_m."<br>";
echo "<b>ID film: </b>".$film_id_m."<br>";
/////////echo time and price///
foreach($cinema[0]->times->time as $k){
$obj=current($k);
$time_b = $obj['time']."\n";
echo "Time: "$time_b."<br>";
foreach($cinema[0]->times as $price){
echo "Price: "$price[0]->pices."<br>";
}
/////////////
echo "<hr>";
}
}