Welcome to WebmasterWorld Guest from 54.146.171.44

Forum Moderators: phranque

Message Too Old, No Replies

Script to pull own XML feed to my homepage

   
2:19 am on Jul 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I created an RSS (RSS 2.0, XML 1.0) file, which is proving a popular headline feed, but I've not yet incorporated it into our own site. We supply the feed, but don't yet display the headlines ourselves!

So I'm looking for a small secure script that will pull the feed from my own directory, and embed the headlines into my own homepage.

I know that there are free proprietry *sites* that do this, but it seems daft to pull the feed from my directory to a server half a world a way, only to have it post the feed contents in a file back in my home directory.

I have MYSQL, but I'd prefer something that doesn't need it.

Anybody help?

Ta!

2:58 am on Jul 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



*Cough*
10:34 am on Jul 14, 2004 (gmt 0)

10+ Year Member



I've been lurking hoping someone else would suggest a clear answer.

The best I could think was to use PHP5 but it's only just been released. The little I understand suggests this can pull xml + xslt and send the output to the user.

I'd look to write a simple XSLT stylesheet for the RSS and use PHP to do the work but this is not something I've tried before and may be dependant on your getting PHP5.. I've no idea whether PHP4 has XML handling.

Good luck.. I'd be interested to know of other approaches to this.

11:03 am on Jul 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Blimey, I actually assumed I was asking one of those daft simple questions everyone knew the answer to, except me.

Is it really so complicated?

Anybody help?

Ta!

11:20 am on Jul 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cold Fusion should do it... lacking that, poke around on the web for a perl script. Should be some out there that do the trick.
11:37 am on Jul 14, 2004 (gmt 0)

10+ Year Member



Introduction to Perl's XML::XSLT module [linuxfocus.org] appears to suggest a simple perl script.

#!/usr/bin/perl
use XML::XSLT;
my $xmlfile = "example.xml";
my $xslfile = "example.xsl";
my $parser = XML::XSLT->new ($xslfile, "FILE");
$parser->transform_document ($xmlfile, "FILE");
$parser->print_result();

Maybe that's all you need?

for a stylesheet you might use something like..

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<h1><xsl:value-of select="title"/></h1>
<p><xsl:value-of select="description" disable-output-escaping="yes" /></p>
</xsl:template>
<xsl:template match="text()@*">
</xsl:template>
</xsl:stylesheet>
12:13 pm on Jul 14, 2004 (gmt 0)

10+ Year Member



.
2:20 am on Jul 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Smashing! That's a start; clear as mud: but a start.

The perl script goes in the cgi-bin, where does the style sheet go?
And what code do I use on an html page to draw and embed the feed data?

Ta!

8:31 am on Jul 16, 2004 (gmt 0)

10+ Year Member



The stylesheet is essentially a template to generate the HTML.

It goes wherever you want it and it's location is suggested by the my $xslfile = "example.xsl"; in the perl. So long as you get the relative location correct it should work.

The xml that the XSL stylesheet/transform works on is your RSS file.

If it does what we expect, the perl should call the XSL to transform the RSS file into HTML. ie. put your rss file location into my $xmlfile = "example.xml";

The transform I suggested is very simple but you can add other html elements to it. The XSL simply copies the HTML to output as it looks for "xsl:" elements.

<xsl:template match="item"> looks for all occurences of elements called 'item'

<xsl:template match="text()@*"> gives you control of the output by simply overwriting the default templates for text and attribute nodes. Otherwise you would get simple dump of the contents of nodes.

The only thing that might complicate this is if you are trying to add other <? scripting?> languages as the XSLT processor will try to understand the contents.. but then I believe there may be ways round that too.

Obviously you need to have the perl XML::XSLT module avaliable.

Hope that helps.

You can find more of an introduction to XML, XSL and others at w3schools [w3schools.com]

[edited by: davidpbrown at 9:10 am (utc) on July 16, 2004]

8:43 am on Jul 16, 2004 (gmt 0)

10+ Year Member



I'm looking at the $parser->print_result(); wondering if perl can insert into an html page. If it can then you might be able to "to draw and embed the feed data".
?
6:25 am on Jul 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For those who like (and use) php this requirement is fulfilled by a free script called MagpieRSS.

But my homepage is plain html, so I'm still scratchin' mi' bonce.

David, since you know more than I, why not try making a simple test rig to see if it works?

ie. Install the script and stylesheet, make a simple feed.xml file, and see if it displays in a .htm file on your site.

6:27 am on Jul 18, 2004 (gmt 0)

WebmasterWorld Senior Member ogletree is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You can set your site to run PHP on .htm pages using the .htaccess file.
6:41 am on Jul 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Care to offer the full .htaccess code to allow php to run on a single .htm page called:

mydomain.com/index.htm

Appreciated ...