display XML data in PHP
My XML output looks like this...
How do I display it in 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>
<?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>";
?>
精彩评论