<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Suman Srinivasan's Code Blog</title>
	<atom:link href="http://sumanrs.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sumanrs.wordpress.com</link>
	<description>Code samples and tutorials during my work/school</description>
	<lastBuildDate>Wed, 07 Jan 2009 21:50:03 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='sumanrs.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/e2aebdde33f65366853a9f2da5330744?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Suman Srinivasan's Code Blog</title>
		<link>http://sumanrs.wordpress.com</link>
	</image>
			<item>
		<title>Fixing Birth Date in phplist</title>
		<link>http://sumanrs.wordpress.com/2009/01/07/fixing-birth-date-in-phplist/</link>
		<comments>http://sumanrs.wordpress.com/2009/01/07/fixing-birth-date-in-phplist/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 21:50:03 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[phplist]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=12</guid>
		<description><![CDATA[If you are using the popular phplist mailing list configuration software, you might run into a situation where the birth date lists only 10 years &#8211; all of which are on or around the current year. How do you fix this to allow your subscribers to view a greater range of dates?

The secret lies in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=12&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you are using the popular phplist mailing list configuration software, you might run into a situation where the birth date lists only 10 years &#8211; all of which are on or around the current year. How do you fix this to allow your subscribers to view a greater range of dates?</p>
<p><span id="more-12"></span></p>
<p>The secret lies in the /config/config.php file that lies in your phplist install. Open up the file, and look for two lines that look like this:</p>
<pre class="brush: php;">
define('DATE_START_YEAR',0);
define('DATE_END_YEAR',0);
</pre>
<p>As you can see from the comments above, the zero value in the fields sets the start and end years to the 10-year limit around the current year.</p>
<p>I changed it to:</p>
<pre class="brush: php;">
define('DATE_START_YEAR',1920);
define('DATE_END_YEAR',2020);
</pre>
<p>for my install, and the phplist shows the 100-year span now.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=12&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2009/01/07/fixing-birth-date-in-phplist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting up registration error messages with Javascript redirect</title>
		<link>http://sumanrs.wordpress.com/2008/08/22/registration-error-messages-javascript-redirect/</link>
		<comments>http://sumanrs.wordpress.com/2008/08/22/registration-error-messages-javascript-redirect/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 17:52:27 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=9</guid>
		<description><![CDATA[OK, got the WORKIT website to output error messages. Both for duplicate entries, as well as incomplete forms. This is how it was done.

1. Set up a PHP function in the header or someplace that outputs this Javascript redirect code upon error.

function redirRegister($str) {
?&#62;
   &#60;script language='Javascript'&#62;window.location='http://www.wirelesskit.net/?page=register&#38;errmsg=&#60;? echo urlencode($str) ?&#62;';&#60;/script&#62;
&#60;?
}

2. Put this error message in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=9&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>OK, got the WORKIT website to output error messages. Both for duplicate entries, as well as incomplete forms. This is how it was done.</p>
<p><span id="more-9"></span></p>
<p>1. Set up a PHP function in the header or someplace that outputs this Javascript redirect code upon error.</p>
<pre class="brush: php;">
function redirRegister($str) {
?&gt;
   &lt;script language='Javascript'&gt;window.location='http://www.wirelesskit.net/?page=register&amp;errmsg=&lt;? echo urlencode($str) ?&gt;';&lt;/script&gt;
&lt;?
}
</pre>
<p>2. Put this error message in the registration form page</p>
<pre class="brush: php;">
if (isset($_GET['errmsg']) {
  $errmsg = $_GET['errmsg'];
  echo '
&lt;b&gt;ERROR&lt;/b&gt;:' .  $errmsg . '
';
}
</pre>
<p>3. In the registration processing page, check for errors. When you come across an error, redirect to the registration form page which outputs the error:</p>
<pre class="brush: php;">
if ($count &gt; 0) {
  redirRegister(&quot;Username exists! Please select another username!&quot;);
} else {
  $result = query(); // Query to insert users; deleted for safety
  if ($result) {
    // Register the user
  } else {
    redirRegister(&quot;Error creating user! Please make sure to fill out all the fields.&quot;);
  }
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=9&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/08/22/registration-error-messages-javascript-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Viewing word count for topics in phpBB3</title>
		<link>http://sumanrs.wordpress.com/2008/07/02/viewing-word-count-topics-phpbb3/</link>
		<comments>http://sumanrs.wordpress.com/2008/07/02/viewing-word-count-topics-phpbb3/#comments</comments>
		<pubDate>Wed, 02 Jul 2008 02:51:13 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[phpbb]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=8</guid>
		<description><![CDATA[Question: you want to be able to see the word count for each post in phpBB3. How do you do that?
Answer: You need to edit two files in the phpBB3 code to get this to work. Read on.

We need to set up a variable called MESSAGE_ROW_COUNT, and display that in the template.
First of all, open [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=8&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Question:</strong> you want to be able to see the word count for each post in phpBB3. How do you do that?</p>
<p><strong>Answer:</strong> You need to edit two files in the phpBB3 code to get this to work. Read on.</p>
<p><span id="more-8"></span></p>
<p>We need to set up a variable called MESSAGE_ROW_COUNT, and display that in the template.</p>
<p>First of all, open <strong>/&lt;phpbb3&gt;/viewtopic.php</strong> and go to near line 1401. This is where the $postrow array is created.</p>
<pre class="brush: php;">
      $postrow = array(
         // more code setting up $postrow elements
      );
</pre>
<p>Somewhere in the middle, add this additional element:</p>
<pre class="brush: php;">
                'MESSAGE_WORD_COUNT'                    =&gt; str_word_count($message),
</pre>
<p>Then go to <strong>/styles/prosilver/template/</strong> and go to line 189, and add this line:</p>
<pre class="brush: xml;">
     &lt;!-- IF postrow.POSTER_POSTS != '' --&gt;&lt;dd&gt;&lt;strong&gt;Word Count:&lt;/strong&gt; {postrow.MESSAGE_WORD_COUNT}&lt;/dd&gt;&lt;!-- ENDIF --&gt;
</pre>
<p>I put this in line 189, where it is just below the name and details of the person who posted the article. However, you may prefer to put it somewhere else.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=8&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/07/02/viewing-word-count-topics-phpbb3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple web framework for web-based CRUD: Ajax CRUD</title>
		<link>http://sumanrs.wordpress.com/2008/07/01/simple-web-framework-ajax-crud/</link>
		<comments>http://sumanrs.wordpress.com/2008/07/01/simple-web-framework-ajax-crud/#comments</comments>
		<pubDate>Tue, 01 Jul 2008 18:20:15 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[bazaar]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=7</guid>
		<description><![CDATA[I&#8217;ve been looking for a while now for a web-based CRUD tool that is simple and works &#8220;out of the box&#8221; and allows me a simpler way to access data than use phpMyAdmin.
I thought CakePHP was the answer, but &#8211; as powerful as it is &#8211; it is hard to set up, especially on the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=7&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been looking for a while now for a web-based CRUD tool that is simple and works &#8220;out of the box&#8221; and allows me a simpler way to access data than use phpMyAdmin.</p>
<p>I thought <a href="http://www.cakephp.org/">CakePHP</a> was the answer, but &#8211; as powerful as it is &#8211; it is hard to set up, especially on the restricted 1and1 accounts that I have on which .htaccess files tend to require some work.</p>
<p>I found this beautiful tool called <a href="http://www.ajaxcrud.com/">Ajax CRUD</a> &#8211; its simple, but enables an easy, AJAX based interface to CRUD functions for your database tables. In fact, it can even do more complicated stuff such as filtering the columns, and some other things.</p>
<p><strong>Sidenote:</strong> Among other things, I was looking at the <a href="http://bazaar-vcs.org/">Bazaar source control system</a> for some software that apparently can be checked out only using Bazaar. I&#8217;m trying to set it up in Eclipse as well, but not too successfully&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=7&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/07/01/simple-web-framework-ajax-crud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>XPath for accessing Flickr&#8217;s popular tags</title>
		<link>http://sumanrs.wordpress.com/2008/05/09/xpath-access-flickr-popular-tags/</link>
		<comments>http://sumanrs.wordpress.com/2008/05/09/xpath-access-flickr-popular-tags/#comments</comments>
		<pubDate>Fri, 09 May 2008 19:09:19 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=6</guid>
		<description><![CDATA[I was finally able my parsing of my Flickr-based project to use XPath instead of iterating through nests of XML elements to get at the daily, weekly and all-time popular tags on Flickr&#8217;s most popular tags page.

These are the XPath tags for getting to the &#60;a&#62; elements on Flickr&#8217;s most popular tags page

// The all-time [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=6&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I was finally able my parsing of my Flickr-based project to use XPath instead of iterating through nests of XML elements to get at the daily, weekly and all-time popular tags on Flickr&#8217;s most popular tags page.</p>
<p><span id="more-6"></span></p>
<p>These are the XPath tags for getting to the &lt;a&gt; elements on Flickr&#8217;s most popular tags page</p>
<pre class="brush: java;">
// The all-time most popular tags
String xpAllTime = &quot;//p[@id='TagCloud']/a&quot;;

// Daily (24 hours) popular tags
String xpDaily = &quot;//table[@id='Recently']/tr/td[1]/p//a&quot;;

// Weekly popular tags
String xpWeekly = &quot;//table[@id='Recently']/tr/td[last()]/p//a&quot;;
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=6&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/05/09/xpath-access-flickr-popular-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Flickr Popular Tags page parsing using Java &#8211; update</title>
		<link>http://sumanrs.wordpress.com/2008/04/30/flickr-popular-tags-parsing-java-update/</link>
		<comments>http://sumanrs.wordpress.com/2008/04/30/flickr-popular-tags-parsing-java-update/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 15:52:34 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[tidy]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=5</guid>
		<description><![CDATA[In my last post on parsing Flickr popular tags I had discussed converting the Flickr page HTML to XML (using Tidy on the command line) and then using the Java XML APIs to get a Document that I could parse.
But I was able to find some sample code of how to use Tidy (jTidy) to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=5&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In my <a href="http://sumanrs.wordpress.com/2008/04/23/parsing-flickr-popular-tags-page/">last post on parsing Flickr popular tags</a> I had discussed converting the Flickr page HTML to XML (using Tidy on the command line) and then using the Java XML APIs to get a Document that I could parse.</p>
<p>But I was able to find some <a href="http://www.lumidant.com/blog/java-html-parsing-library-comparison/">sample code of how to use Tidy (jTidy) to parse HTML</a> and return a Document, so I have changed my code as follows&#8230;</p>
<p><span id="more-5"></span></p>
<pre class="brush: java;">
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import org.w3c.tidy.Tidy;

public class FParser {

	// Main program
	// Much of the XML parsing code comes from
	// http://www.exampledepot.com/egs/org.w3c.dom/pkg.html
	public static void main(String args[]) {
		// The Quintessential Program to Create a DOM Document from an XML File
		startParse(&quot;.&quot;);
	}

	public static void startParse(String dir) {
		Tidy tidy = new Tidy(); // obtain a new Tidy instance
		tidy.setQuiet(true);
		tidy.setShowWarnings(false);
		Document doc = null;
		try {
			FileInputStream fstream = new
				FileInputStream(&quot;2008-4-29_14-30.html&quot;);
			doc = tidy.parseDOM(fstream, null);
		} catch (Exception e) {
			e.printStackTrace();
		}

		// Retrieve the element using id
		NodeList list = doc.getElementsByTagName(&quot;p&quot;);
		for (int i=0; i&lt;list.getLength(); i++) {
			Element element = (Element)list.item(i);
			// We want the &lt;p&gt; whose id is &quot;TagCloud&quot;
			if (element.getAttribute(&quot;id&quot;).equals(&quot;TagCloud&quot;)) {
				// Get each of the Tag Clouds &lt;a&gt; elements
				NodeList list2 = element.getElementsByTagName(&quot;a&quot;);
				for (int j=0; j&lt;list2.getLength(); j++) {
					Element element2 = (Element)list2.item(j);
					// Get the tag by parsing the href attribute
					String sHref = element2.getAttribute(&quot;href&quot;).replaceAll(&quot;/photos/tags/&quot;, &quot;&quot;).replaceAll(&quot;/&quot;,&quot;&quot;);
					// Get the weight by parsing the font-size attribute
					String sStyle = element2.getAttribute(&quot;style&quot;).replaceAll(&quot;font-size: &quot;, &quot;&quot;). replaceAll(&quot;px;&quot;, &quot;&quot;);
					System.out.println(sHref + &quot;: &quot; + sStyle);
				}
			}
		}
	}

	// Parses an XML file and returns a DOM document.
	// If validating is true, the contents is validated against the DTD
	// specified in the file.
	public static Document parseXmlFile(String filename, boolean validating) {
		try {
			// Create a builder factory
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			factory.setValidating(validating);

			// Create the builder and parse the file
			Document doc = factory.newDocumentBuilder().parse(new File(filename));
			return doc;
		} catch (SAXException e) {
			// A parsing error occurred; the xml input is not valid
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
}
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=5&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/04/30/flickr-popular-tags-parsing-java-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Parsing Flickr&#8217;s Popular Tags page</title>
		<link>http://sumanrs.wordpress.com/2008/04/23/parsing-flickr-popular-tags-page/</link>
		<comments>http://sumanrs.wordpress.com/2008/04/23/parsing-flickr-popular-tags-page/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 20:35:29 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[flickr]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=4</guid>
		<description><![CDATA[For my Visual Databases course (again), one of my project goals is to be able to parse Flickr&#8217;s most popular tags page, save the results over the course of a few days, and check the variation of the popular tags with time. And on my Windows desktop&#8230;
OK, here is what I did.

1. Wrote a Windows [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=4&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For my Visual Databases course (again), one of my project goals is to be able to parse <a href="http://www.flickr.com/tags/">Flickr&#8217;s most popular tags</a> page, save the results over the course of a few days, and check the variation of the popular tags with time. And on my Windows desktop&#8230;</p>
<p>OK, here is what I did.<br />
<span id="more-4"></span></p>
<p>1. Wrote a Windows shell script to pull down the Flickr&#8217;s popular tags page every day, save it to the folder. (I had Cygwin installed and used its curl binary to download the page.) This saves files with names like this: <em>2008-4-22_14-30.html</em> .</p>
<pre class="brush: vb;">

dYear = DatePart(&quot;yyyy&quot; , Now)
dMonth = DatePart(&quot;m&quot; , Now)
dDay = DatePart(&quot;d&quot; , Now)
dHour = DatePart(&quot;h&quot;, Now)
dMinute = DatePart(&quot;n&quot; , Now)
dSeconds = DatePart(&quot;s&quot; , Now)

fileName = dYear &amp; &quot;-&quot; &amp; dMonth &amp; &quot;-&quot; &amp; dDay  &amp; &quot;_&quot; &amp; dHour  &amp; &quot;-&quot; &amp; dMinute
Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
WshShell.Run (&quot;c:\cygwin\bin\curl.exe http://flickr.com/photos/tags/ -o &quot; &amp; fileName &amp; &quot;.html&quot;)
</pre>
<p>2. Set up a Scheduled Task in Windows to run this script daily at 2:30 pm.</p>
<p>So now, I can get several days worth of Flickr&#8217;s most popular tags page. On to parsing.</p>
<p>3. Java does not let you parse HTML easily. So I convert the HTML pages to XHTML using an online version of Tidy (this is manual for now).</p>
<p>4. Wrote a Java program that parses this XHTML page and outputs the tags and their &#8220;weight&#8221;, measured in font size.</p>
<pre class="brush: java;">

import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;

public class FParser {

    // Main program
    // Much of the XML parsing code comes from
    // http://www.exampledepot.com/egs/org.w3c.dom/pkg.html
    public static void main(String args[]) {
        // The Quintessential Program to Create a DOM Document from an XML File
        Document doc = parseXmlFile(&quot;flickr.xml&quot;, false);

        // Retrieve the element using id
        NodeList list = doc.getElementsByTagName(&quot;p&quot;);
        for (int i=0; i&lt;list.getLength(); i++) {
            Element element = (Element)list.item(i);
            // We want the &lt;p&gt; whose id is &quot;TagCloud&quot;
            if (element.getAttribute(&quot;id&quot;).equals(&quot;TagCloud&quot;)) {
                // Get each of the Tag Clouds &lt;a&gt; elements
                NodeList list2 = element.getElementsByTagName(&quot;a&quot;);
                for (int j=0; j&lt;list2.getLength(); j++) {
                    Element element2 = (Element)list2.item(j);
                    // Get the tag by parsing the href attribute
                    String sHref = element2.getAttribute(&quot;href&quot;).replaceAll(&quot;/photos/tags/&quot;, &quot;&quot;).replaceAll(&quot;/&quot;,&quot;&quot;);
                    // Get the weight by parsing the font-size attribute
                    String sStyle = element2.getAttribute(&quot;style&quot;).replaceAll(&quot;font-size: &quot;, &quot;&quot;). replaceAll(&quot;px;&quot;, &quot;&quot;);
                    System.out.println(sHref + &quot;: &quot; + sStyle);
                }
            }
        }

    }

    // Parses an XML file and returns a DOM document.
    // If validating is true, the contents is validated against the DTD
    // specified in the file.
    public static Document parseXmlFile(String filename, boolean validating) {
        try {
            // Create a builder factory
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(validating);

            // Create the builder and parse the file
            Document doc = factory.newDocumentBuilder().parse(new File(filename));
            return doc;
        } catch (SAXException e) {
            // A parsing error occurred; the xml input is not valid
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
</pre>
<p>To-do:</p>
<p>5. Save this data for each day in some sort of database of Excel spreadsheet.</p>
<p>6. Plot the values to see if the tags change over time and if their weight changes too&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=4&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/04/23/parsing-flickr-popular-tags-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting form values in jQuery</title>
		<link>http://sumanrs.wordpress.com/2008/04/16/setting-form-values-jquery/</link>
		<comments>http://sumanrs.wordpress.com/2008/04/16/setting-form-values-jquery/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 19:10:54 +0000</pubDate>
		<dc:creator>sumanrs</dc:creator>
				<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://sumanrs.wordpress.com/?p=3</guid>
		<description><![CDATA[For my assignment in &#8220;Visual Databases&#8221;, one of my projects involved having a hidden form value set using Javascript. The value would be set to the id of the div when the mouse moved over one of the div elements.
Since I was using jQuery, I looked around for some code that would enable me to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=3&subd=sumanrs&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For my assignment in &#8220;Visual Databases&#8221;, one of my projects involved having a hidden form value set using Javascript. The value would be set to the id of the div when the mouse moved over one of the div elements.</p>
<p>Since I was using jQuery, I looked around for some code that would enable me to do this using jQuery, and this was the result:<br />
<span id="more-3"></span></p>
<p><strong>Javascript (in &lt;head&gt;):</strong></p>
<pre class="brush: jscript;">
 $(document).ready(function(){
   // other functions
   $(&quot;div.photo&quot;).mouseover(function() {
     $(&quot;div.photo&quot;).css({backgroundColor:&quot;white&quot;});
     $(this).css({backgroundColor:&quot;blue&quot;});
     var idval = $(this).attr(&quot;id&quot;);
     $(&quot;input#pcompid&quot;).val(idval);
   });
 });
</pre>
<p><strong>HTML in body:</strong></p>
<pre class="brush: xml;">
&lt;form action=&quot;&quot;&gt;
&lt;input type=&quot;hidden&quot; id=&quot;pcompid&quot; name=&quot;pcompid&quot; value=&quot;&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;Compare&quot;&gt;
&lt;/form&gt;

&lt;div class='photo' id='2419405422'&gt;
&lt;a href=&quot;morephotos.php?photoid=2419405422&quot;&gt;
&lt;img border='0'&gt;
&lt;/a&gt;&lt;/div&gt;
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sumanrs.wordpress.com/3/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sumanrs.wordpress.com/3/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sumanrs.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sumanrs.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sumanrs.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sumanrs.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sumanrs.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sumanrs.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sumanrs.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sumanrs.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sumanrs.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sumanrs.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sumanrs.wordpress.com&blog=3501934&post=3&subd=sumanrs&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sumanrs.wordpress.com/2008/04/16/setting-form-values-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ebb1ed81de910c666ddf931fbf261904?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sumanrs</media:title>
		</media:content>
	</item>
	</channel>
</rss>