我的XML输出看起来像这样......
如何在PHP中显示它?
<row>
<field name="seat_no">18</field>
<field name="my_ticket_no">924403</field>
<field name="pass_nm">abcd</field>
<field name="pass_age">46</field>
<field name="pass_sex">F</field>
</row>
<row>
<field name="seat_no">19</field>
<field name="my_ticket_no">926634</field>
<field name="pass_nm">VANDANA</field>
<field name="pass_age">25</field>
<field name="pass_sex">F</field>
</row>
答案 0 :(得分:2)
<?php
$data = new SimpleXMLElement('<root><row>
<field name="seat_no">18</field>
<field name="my_ticket_no">924403</field>
<field name="pass_nm">abcd</field>
<field name="pass_age">46</field>
<field name="pass_sex">F</field>
</row>
<row>
<field name="seat_no">19</field>
<field name="my_ticket_no">926634</field>
<field name="pass_nm">VANDANA</field>
<field name="pass_age">25</field>
<field name="pass_sex">F</field>
</row></root>');
echo "<table border='1'>";
foreach($data->row as $row)
{
echo "<tr>";
$seat = $row->xpath("field[@name = 'seat_no']");
echo "<td>".$seat[0]."</td>";
$tckt = $row->xpath("field[@name = 'my_ticket_no']");
echo "<td>".$tckt[0]."</td>";
//and so on...
echo "</tr>";
}
echo "</table>";
?>