Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/69424-parsing-an-xml-file-into-a-table/
Share on other sites

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?

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.