echo "<li><a href=". $item ["link"]. ">".
$item ["title"]. "</a>",
}
}
?>
</ul>
Each time you reload the above script, the corresponding RDF file is taken from a specific location, and after analysis, it is displayed in the required format.
If your site has a high volume of traffic, you may find our hard work meaningless, especially if the RDF data is not being updated as quickly. In this case, perhaps it would be wise to explore the local caching of RDF data: either extend the above example program to include caching in it, or spend a few hours a day on downloading a local copy of the latest RDF file to your Web server, and then use this local copy, Rather than the "live" one.
8 Complimentary lunch (A free lunch)
The class I wrote above is also very basic, is to illustrate the problem, perhaps also can be used for low traffic site. If you're looking for something more professional, go online, there are many open source RDF parsers with a variety of additional features (including caching). So let's look at some examples of how to use these analyzers.
The first one to talk about is the RDF parser class developed by Stefan Saasen for the FASE4 Web site, which can be downloaded free of charge from http://www.fase4.com/rdf/. This is a full-featured RDF parser that supports caching and proxy authentication. Here is an example of how to use it:
<style type= "Text/css" >
Body {Font-family:verdana, font-size:11px,}
. fase4_rdf {font-size:13px, font-family:verdana}. Fase4_rdf_title
{font-size:13px, Font-weight:bolder,}
</style>
<body>
?
Include class
Include ("rdf.class.php"),
Instantiate object
$RDF = new FASE4_RDF,
Set number of items to display
$RDF->set_max_item (5),
Set RDF engine options
$RDF->use_dynamic_display (True),
$RDF->set_options (Array ("image" => "hidden", "TextInput" => "hidden")),
Parse and display data
$RDF->PARSE_RDF ("HTTP://WWW.FRESHMEAT.NET/BACKEND/FM-RELEASES.RDF"),
$RDF->finish (),
?>
</body>
Another introduction is the PHP RDF parser developed by Jason Williams, which can be downloaded in http://www.nerdzine.net/php_rdf/. This is a PHP class without any rendering, and implements some basic methods. But it contains a lot of attributes that allow you to schedule processed data until you are satisfied.
<basefont face= "Verdana" >
<body link= "Red" vlink= "red" alink= "Red" >
?
Include ("rdf_class.php"),
This is needs to is a local file
$f = new Rdffile ("./fm-releases.rdf"),
$f->parse (True),
$f->returntable (True, "Black", "white", "100%"),
?>
</body>
Documents about these classes are presented on their respective websites.
9 Add a little style (adding a Little style)
In case you hate iterating through those php arrays and tagging them in HTML, you can also choose to format and display the data by using an XSLT style sheet. PHP4 1 can support the Sablotron XSLT processor with the new XSLT APIs, which can be used to merge an XSLT style sheet and an XML document (here, the RDF file), making it very easy to translate XML tags into browser-readable HTML tags.
I don't want to be too thin on this, you can take a look at the PHP manual, or focus on the links later in this article for more detailed information. However, I will give a simple example to illustrate this problem. First, give the style sheet file:
<?xml version= "1.0"?>
<xsl:stylesheet xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform"
xmlns:rdf= "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
Xmlns:rss= "http://purl.org/rss/1.0/"
Xmlns:dc= "HTTP://PURL.ORG/DC/ELEMENTS/1.1/" version= "1.0" >
<!--Main Page-->
<xsl:template match= "/RDF:RDF" >
<basefont face= "Arial" size= "2"/>
<body>
<xsl:apply-templates select= "Rss:channel"/>
<ul>
<xsl:apply-templates select= "Rss:item"/>
</ul>
</body>
</xsl:template>
<!--Channel-->
<xsl:template match= "Rss:channel" >
<b>
<a>
<xsl:attribute name= "href" ><xsl:value-of select= "Rss:link"
/></xsl:attribute>
<xsl:value-of select= "Rss:title"/>
</a>
</b>
</xsl:template>
<!--item-->
<xsl:template match= "Rss:item" >
<li/>
<a>
<xsl:attribute name= "href" ><xsl:value-of select= "Rss:link"
/></xsl:attribute>
<xsl:value-of select= "Rss:title"/>
</a>
<br/>
<xsl:value-of select= "Rss:description"/>
</xsl:template>
</xsl:stylesheet>
Here is a PHP script to combine the above style sheet with the "Fresh Meat" RDF document to generate an HTML page:
<?php
XML file
This is needs to is a local file
$xml = "FM-RELEASES.RDF",
XSLT file
$XSLT = "Fm.xsl",
Create a new XSLT processor
$XP = Xslt_create (),
Transform the XML file as per the XSLT stylesheet
Return to $result
$result = Xslt_process ($xp, $xml, $XSLT),
if ($result)
{
Print it
Echo $result,
}
Clean up
Xslt_free ($XP),
?>
I think it is quite simple and needless to say. Two of documents are merged together to produce the following "synthetics":
This is another way to convert RDF data into browser-readable HTML, which may be simpler (though not ideal). Note, however, that you need to run an external program to periodically update your local copy of your RDF file because the PHP XSLT processor may have difficulty accessing the remote file.
10) Homework (homework)
If you are interested in learning more about the techniques mentioned in these texts and not talked about, you may consider accessing the following links:
RSS 1.0 Specification:
http://www.purl.org/rss/1.0/
RSS History:
http://backend.userland.com/stories/rss091
Content of RDF on the website of the Consortium:
http://www.w3.org/RDF/
Discussion of sax and DOM programming in PHP: Http://www.devshed.com/Server_Side/XML/XMLwithPHP
Discussion of implementing XSLT transformations in PHP:
Http://www.devshed.com/Server_Side/XML/XSLTrans
Discussion of PHP classes:
Http://www.devshed.com/Server_Side/PHP/BackToClass