h0me5k1n Posted September 15, 2007 Share Posted September 15, 2007 I'm trying to parse an xml file into a table on a webpage. I'm using php5 which, I believe, doesn't support xsltproc anymore (since xml support was rewritten for php5). I have got it working on my home server using xsltproc and an xsl file on the command line (unix) but I want to transfer it to a host which doesn't have xsltproc installed and have the xml file parsed into a table by php because I know it can be done. The actual page that I'm trying to parse is here Can anyone give me any pointers/links/howtos for parsing xml files into a table using php? Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/ Share on other sites More sharing options...
effigy Posted September 15, 2007 Share Posted September 15, 2007 What do you mean by xsltproc? This is available in 4. Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-348820 Share on other sites More sharing options...
h0me5k1n Posted September 15, 2007 Author Share Posted September 15, 2007 By xsltproc I mean the commandline application. I'm not using php4 and as xml support was rewritten in php5 using libxml (?). I basically want to create a table showing the contents of the xml page below using php xml parsing. Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-348833 Share on other sites More sharing options...
h0me5k1n Posted September 15, 2007 Author Share Posted September 15, 2007 OK I figured most of it out: <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <table border="1"> <tr> <th>Channel</th> <th>Group</th> <th>Name</th> <th>Sopcast Link</th> <th>Network Quality</th> <th>Source Quality</th> <th>kbps</th> <th>User Count</th> <?php // set the XML file name as a PHP string $ChannelList = "chlist.xml" ; // load the XML file $xml = @simplexml_load_file($ChannelList) or die ("no file loaded") ; foreach ($xml->group as $group) { // echo "Channel name is " . $group->channel->name ; foreach ($group->channel as $channel) { echo "<tr><td>" . $channel['id'] . "</td>" ; echo "<td>" . $channel->class['en'] . "</td>" ; echo "<td>" . $channel->name['en'] . "</td>" ; echo "<td>" . $channel->sop_address->item . "</td>" ; echo "<td>" . $channel->qc . "</td>" ; echo "<td>" . $channel->qs . "</td>" ; echo "<td>" . $channel->kbps . "</td>"; echo "<td>" . $channel->user_count . "</td>" ; } echo "</tr>" ; } ?> </table> </body> </html> Now anyone know how do I sort the output? For example by channel id, name or class? Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-349065 Share on other sites More sharing options...
h0me5k1n Posted September 15, 2007 Author Share Posted September 15, 2007 The above code parses the xml file into a table but I can't figure out how to sort the entries. Does anyone know how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-349262 Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 You've already put it into a multidimensional array... Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-349272 Share on other sites More sharing options...
h0me5k1n Posted September 15, 2007 Author Share Posted September 15, 2007 Sounds like you're saying I'm mad? Is there not a command I can use to easily sort the output? Do I need to send the output into an array before I can sort it? (I'm just probing for ideas cos this is killing me) Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-349278 Share on other sites More sharing options...
rarebit Posted September 15, 2007 Share Posted September 15, 2007 There's lot's of way's to sort array's in php, take a look at this and find the 'see also'... http://uk3.php.net/manual/en/function.sort.php What I was saying is, it's already in an array and you can arrange it any mad freakin way you want... I'm now presuming there coming out in the wrong order? Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-349280 Share on other sites More sharing options...
h0me5k1n Posted September 15, 2007 Author Share Posted September 15, 2007 thanks for the quick reply rarebit - I'll take a look at your link and post my results. They are coming out in the wrong order (IMO). Quote Link to comment https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/#findComment-349282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.