0

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>
4
  • ... I don't get it. Why would PHP need to display it? Why not just put it in a file and serve that? Commented Jan 27, 2010 at 11:48
  • why not use xml and xsl to display the data in php? Commented Jan 27, 2010 at 11:49
  • 2
    What do you mean by displaying it in PHP? Commented Jan 27, 2010 at 11:49
  • This is probably a valid question asking for how to format / layout raw XML data in PHP. We need more hints as what the end result is supposed to look like, though. Commented Jan 27, 2010 at 11:53

1 Answer 1

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>";
?>
Sign up to request clarification or add additional context in comments.

1 Comment

I need to display the data in a normat table format. <table> <tr> <td> 18 </td> <td> 924403</td> <td>abcd</td> <td>46</td> <td> F </td></tr> .(second row here)..</table>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.