0

I have a website with a table that is populated with data from various external XML feeds. The table is generated using Javascript as after some reading, I found that this seemed to be the best approach for creating an HTML table from XML data (please correct me if wrong!).

I now want to parse this HTML table in to an RSS feed and I'm struggling to find the best way to do so. I have php code that will parse an HTML table, but because this table is generated using JS (ie. client side) the PHP parser does not work. Can anyone tell me the best way to go about this?

As you've probably gathered, I'm quite new to programming so layman terms would be much appreciated where possible.

Thanks a lot.

Chris
  • 57
  • 1
  • 1
  • 7

2 Answers2

1

I found that this seemed to be the best approach for creating an HTML table from XML data (please correct me if wrong!).

As a rule of thumb, if instant feedback isn't required (and it isn't if you are fetching data from multiple external sources), if you can do it server side, then do it server side. You only have one server side environment to deal with instead of dozens of different client side environments (some of which could have JS turned off).

I now want to parse this HTML table in to an RSS feed and I'm struggling to find the best way to do so. I have php code that will parse an HTML table, but because this table is generated using JS (ie. client side) the PHP parser does not work. Can anyone tell me the best way to go about this?

Write PHP to get the data from wherever the JS gets its data from. You already have the logic to query it in JS, so you should be able to do a fairly straight port of that.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks Quentin. Sorry, I've been trying to figure out how to do it server side using PHP but haven't had much luck. Could you point me in the general direction for how to do this? Would be a great help. Thanks again. – Chris May 23 '11 at 16:06
  • This is a great answer; it strikes at the root. – Ziggy Mar 08 '13 at 07:50
1

It is not possible to generate an RSS feed from pure JavaScript, as most RSS clients don't speak JavaScript, and the standard doesn't provide for it - you won't be able to run the commands required to create the data.

Replicate the functionality of your JavaScript aggregator using some server-side language like PHP, and build an RSS feed from it. It will require rewriting your entire code, but probably is the best way to go.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Thanks a lot Pekka for the response. I feared that would be the case. I have been trying to find some code snippets to help me use php to generate the HTML table instead of javascript but I'm having no luck. Do you know what I should be looking for and whether this is quite a straightforward thing to do? – Chris May 23 '11 at 15:59
  • @Chris mm, creating the table is pretty straightforward. To get the XML, you'd use an XML parser like one featured here: [Best XML Parser for PHP](http://stackoverflow.com/q/188414) – Pekka May 23 '11 at 16:11