Plugging RDF Content Into Your Web Site With PHP - Switching Channels (
Page 3 of 9 )
An RSS document
typically contains a list of resources (URLs), marked up with descriptive
metadata. Here's an example:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="http://www.melonfire.com/">
<title>Trog</title>
<description>Well-written technical articles and
tutorials on Web technologies</description>
<link>http://www.melonfire.com/community/columns/trog/</link>
<items>
<rdf:Seq>
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
</rdf:Seq>
</items>
</channel>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=10
0">
<title>Building A PHP-Based Mail Client (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=100
</li
nk>
<description>Ever wondered how Web-based mail clients
work? Find out here.</description>
</item>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=71">
<title>Using PHP With XML (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=71<
/link>
<description>Use PHP's SAX parser to parse XML data and
generate HTML pages.</description>
</item>
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=62">
<title>Access Granted</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=62<
/link>
<description>Precisely control access to information
with the mySQL grant tables.</description>
</item>
</rdf:RDF>
As you can see, an RDF file is split up into very
clearly-demarcated sections. First comes the document prolog,
<?xml version="1.0" encoding="UTF-8"?>
and namespace declarations in the root element.
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">
This is followed by a <channel> block, which contains
general information on the channel that is described by this RDF file. In the
example above, the channel is Melonfire's Trog column, which gets updated every
week with new technical articles and tutorials.
<channel rdf:about="http://www.melonfire.com/">
<title>Trog</title>
<description>Well-written technical articles and
tutorials on Web technologies</description>
<link>http://www.melonfire.com/community/columns/trog/</link>
<items>
<rdf:Seq>
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
</rdf:Seq>
</items>
</channel>
The <channel> block contains an <items> block,
which contains a sequential list of all the resources described within the RDF
document. This list is formulated as a series of <li /> elements, which
may be familiar to you from HTML. Every resource in this block corresponds to a
resource described in greater detail in a subsequent <item> block (further
down).
<items>
<rdf:Seq>
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=100" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=71" />
<li
rdf:resource="http://www.melonfire.com/community/columns/trog/article.ph
p?id
=62" />
</rdf:Seq>
</items>
It's also possible to intersperse an <image> block at
this stage, in case you'd like to publish the URL of your channel's logo.
And now for the meat. Every <item> block in an RSS 1.0 document
describes a single resource in greater detail, providing a title, a URL and a
description of that resource.
<item
rdf:about="http://www.melonfire.com/community/columns/trog/article.php?i
d=71">
<title>Using PHP With XML (part 1)</title>
<link>http://www.melonfire.com/community/columns/trog/article.php?id=71<
/link>
<description>Use PHP's SAX parser to parse XML data and
generate HTML pages.</description>
</item>
In this example, the <item> block above describes a
single article in the Trog "channel", providing a description and title for it,
and including a URL so that a content aggregator can create backward links to
it.
As you can see, an RSS 1.0 file is fairly straightforward, and it's
quite easy to create one, either manually or programmatically. The example and
explanation above was merely illustrative; there's a lot more you can do with
RSS 1.0 and RDF in general, and you should take a look at the links provided at
the end of this article for more information. Until we get there, though, let's
spend a few more minutes discussing how an RSS 1.0 document like the one above
can be plugged into your own Web site.