≡ Menu


Rinse First is now availible for syndication! In other words, if you have an RSS feeder, or a desire to put the titles and descriptions of my posts on another site, you can now do that! Here’s a little bit more on RSS and the domxml code I’m using to get the job done:

RSS seems to stand for two or three different things. My favorite so far is Really Simple Syndication, but I don’t know if that’s right. It’s basically XML with a very specific name space. If you don’t know what I’m saying, thats ok, all you need to know is that it’s a tree. It has leaves, nodes, and branchs. Yay right?

That begs the question, how am I generating this RSS feed. Well, most people would go the simple route and generate the code manually by printing out the proper tags for xml. To me, that’s a waste. It might be faster computation wise, and it might be easier education wise, but it’s not grasping the full power of XML and trees.

Instead, I used php’s domxml functions to get the job done. I basically build the tree from my entry database, and then spit it out as the RSS feed. This helps to insure the tree gets built properly and it allows me to add nodes without breaking the rest of the tree at any time.

Pretty cool huh? I bet in this 800th post, the last thing you were looking for was code:

I first create the root node structure, followed by all the nodes that describe the channel:

$doc = domxml_open_mem(‘<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" />’);
$root = $doc->document_element();
$node = $doc->create_element("channel");
$node_title = $doc->create_element("title");
$node_link = $doc->create_element("link");
$node_description = $doc->create_element("description");
$node_lang = $doc->create_element("language");

I then populate each node and attach it to the tree using code like the following:

$channel_node = $root->append_child($node);
$title_node = $channel_node->append_child($node_title);
$title_node->set_content("Rinse First");

$link_node = $channel_node->append_child($node_link);

$description_node = $channel_node->append_child($node_description);
$description_node->set_content("my site");

$language_node = $channel_node->append_child($node_lang);

We then need to spit out each post that we wish to have put in the feed. I use a while loop to do this for my 10 most recent posts:

while($item_row = mysql_fetch_array($result)){
$node_item = $doc->create_element("item");
$item_node = $channel_node->append_child($node_item);

$node_title = $doc->create_element("title");
$title_node = $item_node->append_child($node_title);

$node_link = $doc->create_element("link");
$link_node = $item_node->append_child($node_link);
$link_node->set_content(‘http://www.rinsefirst.com/index.php?section=archive&sectiontitle=The%20Day&ref_id=’. $item_row[‘id’]);

Notice the utf8-encode here. That’s due to the fact that XML is supposed to be encoded into utf8. If it’s not, you should do that.

$node_link = $doc->create_element("description");
$link_node = $item_node->append_child($node_link);

$node_link = $doc->create_element("dc:creator");
$link_node = $item_node->append_child($node_link);
$link_node->set_content("Justin Gehring (JJ Doughboy)");

$node_link = $doc->create_element("dc:date");
$link_node = $item_node->append_child($node_link);


I think tomorrow I’ll post the code in it’s entirity, maybe with some better comments or something. OR MAYBE, I’ll start working on a new section to this site. I don’t know, if you have any questions about my RSS feed and how it works, drop me an email. Have a great night all

Next post:

Previous post: