我有一个非常简单的XML文件:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Data><Day Num="4197">
<Date>270611</Date>
<Energy>47</Energy>
</Day>
<Day Num="4219">
<Date>190711</Date>
<Energy>202</Energy>
</Day>
<Day Num="4220">
<Date>200711</Date>
<Energy>17074</Energy>
</Day>
<Day Num="4221">
<Date>210711</Date>
<Energy>11563</Energy>
</Day>
<Day Num="4222">
<Date>220711</Date>
<Energy>18178</Energy>
</Day>
<Day Num="4223">
<Date>230711</Date>
<Energy>24916</Energy>
</Day>
<Day Num="4224">
<Date>240711</Date>
<Energy>10555</Energy>
</Day>
<Day Num="4225">
<Date>250711</Date>
<Energy>12683</Energy>
</Day>
</Data>
昨天我在这里得到了一些帮助,我把它拉出日期和能量,但现在我想要显示Day Num。
我做了一个print_r($ xml);显示:
SimpleXMLElement Object
(
[Day] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Num] => 4197
)
[Date] => 270611
[Energy] => 47
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Num] => 4219
)
[Date] => 190711
[Energy] => 202
)
所以我想要的Num字段是一个数组,但我无法弄清楚如何提取它?
我目前的代码非常简单,它是:
$xml = simplexml_load_file("DATA.XML");
foreach($xml->children() as $day)
{
list($date, $energy) = $day->children();
echo ',Date: ' . $date . ', Energy: ' . $energy . '<br />';
}
我如何提取Day Num?