homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque & physics

Webmaster General Forum

Script to pull own XML feed to my homepage

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

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?




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



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

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)

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?



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

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)

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

use XML::XSLT;
my $xmlfile = "example.xml";
my $xslfile = "example.xsl";
my $parser = XML::XSLT->new ($xslfile, "FILE");
$parser->transform_document ($xmlfile, "FILE");

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="/">
<xsl:template match="item">
<h1><xsl:value-of select="title"/></h1>
<p><xsl:value-of select="description" disable-output-escaping="yes" /></p>
<xsl:template match="text()@*">


 12:13 pm on Jul 14, 2004 (gmt 0)



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

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?



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

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)

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)

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)

You can set your site to run PHP on .htm pages using the .htaccess file.


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

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


Appreciated ...

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved