<?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/"
	>

<channel>
	<title>Robertdot, A Web Design Blog &#187; Chat</title>
	<atom:link href="http://robertdot.org/tags/chat/feed/" rel="self" type="application/rss+xml" />
	<link>http://robertdot.org</link>
	<description>A web design blog for designers that develop or developers that design.</description>
	<lastBuildDate>Fri, 05 Mar 2010 15:59:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To Make an Ajax Chat Room</title>
		<link>http://robertdot.org/2006/06/23/how-to-make-an-ajax-chat-room/</link>
		<comments>http://robertdot.org/2006/06/23/how-to-make-an-ajax-chat-room/#comments</comments>
		<pubDate>Fri, 23 Jun 2006 14:03:46 +0000</pubDate>
		<dc:creator>Robert</dc:creator>
				<category><![CDATA[Web Design]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Chat]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://robertdot.org/2009/01/14/how-to-make-an-ajax-chat-room/</guid>
		<description><![CDATA[
 I&#8217;ve been helping this guy from India with an Ajax / XML chat app.  I wrote one ages ago, but I think it broke.  So, since I&#8217;m already giving a how-to, I might as well write it down.

Ajax For Newbies

 If you are familiar with XML, the buzzword Ajax, the XMLHttpRequest() object, [...]]]></description>
			<content:encoded><![CDATA[<p>
 I&#8217;ve been helping this guy from India with an <acronym title="Asynchronous Javascript and XML">Ajax</acronym> / <acronym title="Extensible Markup Language">XML</acronym> chat <abbr title="application">app</abbr>.  I wrote one ages ago, but I think it broke.  So, since I&#8217;m already giving a how-to, I might as well write it down.
</p>
<h2 id="sect1">Ajax For Newbies</h2>
<p>
 If you are familiar with XML, the buzzword <q>Ajax</q>, the <code>XMLHttpRequest()</code> object, and <acronym title="Document Object Model">DOM</acronym> scripting, skip to the <a href="#sect2">juicy part</a>.  If not, keep on reading.
</p>
<h3 id="sect1.1">An XML Primer for Ajax</h3>
<p>
 XML looks kind of like <acronym title="Hypertext Markup Language">HTML</acronym>, but it is quite different.  For the sake of brevity, XML is a structured data file that draws from <acronym title="Standard Generalized Markup Language">SGML</acronym>.  The difference is that it <em>must</em> be well formed and that the tags can be <q>arbitrarily</q> named (unless you specify a <acronym title="Document Type Definition">DTD</acronym>).
</p>
<p>
 Going into more detail would not be pragmatic since the JavaScript XML parsers only care about whether or not the XML is well-formed.  So, here is an example XML file:
</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;messages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;from<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   Fred
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/from<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   Fred here... Just making a post!
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;from<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   Joey
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/from<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   Hey, Fred.  Thanks for the post.
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/message<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/messages<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>
 The good thing about good XML is that it has metadata built in.  You can read it and know what is what.  The code above is obviously a group of messages.  Inside the messages group is a message.  In this case, there are two of them.  Inside each message is a from and a body.  The from, of course, contains the name of the person who sent the message.  It follows that the body contains the message body.  This XML file will be used later.
</p>
<h3 id="sect1.2">XMLHttpRequest Primer for Ajax</h3>
<p>
 <code>XMLHttpRequest</code>, at least on browsers that aren&#8217;t Internet Explorer 6 or less, is a native object in JavaScript that allows the client to send a request to the server <q>in the background.</q>  That is, the browser doesn&#8217;t have to physically go to the page.  This makes it easy to update parts of pages without <code>iframe</code>, <code>frame</code> and other hacks.
</p>
<p>
 I&#8217;ll give you the condensed version of how to use it for the sake of brevity.  I&#8217;m sort of copy / pasting code from <a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html">Apple&#8217;s Developer documents</a> because their example does <code>XMLHttpRequest()</code> the <em>right</em> way.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// This needs to be in the global scope so we can use it in other functions.</span>
<span style="color: #003366; font-weight: bold;">var</span> xml_obj<span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">/*
&nbsp;
 We will be sending loadXMLDoc the url of the page we want to call,
 the query string to post to the url, and a function to call when
 the script updates.
&nbsp;
*/</span>
<span style="color: #003366; font-weight: bold;">function</span> loadXMLDoc<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>query_string<span style="color: #339933;">,</span>callback<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	xml_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// Try native XMLHttpRequest first.</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">XMLHttpRequest</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    	<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			xml_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			xml_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">// If native fails, fall back to IE's ActiveX objects.</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">ActiveXObject</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       	<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        	xml_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        	<span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
          		xml_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          		xml_obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        	<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xml_obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// Any time the state of the request changes, callback will be called.</span>
		xml_obj.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> callback<span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// Set the parameters of the request.</span>
		<span style="color: #006600; font-style: italic;">// POST can also be GET.  We use the URL from above.</span>
		<span style="color: #006600; font-style: italic;">// The &lt;q&gt;true&lt;/q&gt; tells whether the request should be asynchronous.</span>
		xml_obj.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		xml_obj.<span style="color: #660066;">setRequestHeader</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-Type&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;application/x-www-form-urlencoded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// Since we are POSTing, we send the query string as a header</span>
		<span style="color: #006600; font-style: italic;">// instead of as a string at the end of the URL.</span>
		xml_obj.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>query_string<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Failed to create XMLHttpRequest!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">/*
&nbsp;
This is an example callback function.
&nbsp;
*/</span>
<span style="color: #003366; font-weight: bold;">function</span> messagesRetrieved<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>xml_obj.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// When readyState is 4, the request is complete.</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>xml_obj.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// When status is 200, we know there are no server errors or anything.</span>
			<span style="color: #006600; font-style: italic;">// and we can process the data.</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;There was a problem retrieving the XML data:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> xml_obj.<span style="color: #660066;">statusText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// How we would call the loadXMLDoc</span>
loadXMLDoc<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://domain.com/myurl.php&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;action=get_messages&quot;</span><span style="color: #339933;">,</span>messagesRetrieved<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>
 Hopefully, from the comments in the script, you can see what is going on.  When the request starts, the <code>xml_obj.readyState</code> property will be update.  Once the request is complete, there will be several properties available.
</p>
<ul>
<li><code>xml_obj.responseXML</code> is the most important for Ajax, since that is where the data is stored as an object.  Yes, JavaScript automagically parses the XML and puts it in an object <em>for</em> you.</li>
<li><code>xml_obj.responseText</code> is nice because it will print out the text returned from the server.  It&#8217;s great for debugging.</li>
<li><code>xml_obj.status</code> is the server status code of the request.  This should be <samp>200</samp> or something is wrong with your scripts.</li>
</ul>
<h3 id="sect1.3">What is Ajax About, Then?</h3>
<p>
 As I said, the term <q>Ajax</q> is a buzzword.  It&#8217;s a short way of saying, <q>JavaScript using <code>XMLHttpRequest</code> to get XML from a server in the background.</q>
</p>
<p>
 There are other methods that are probably get called Ajax, but aren&#8217;t.  For example, <code>XMLHttpRequest</code> allows the server to send back text instead of XML (<q><acronym title="Asynchronous JavaScript and Text">Ajat</acronym></q>?).  Also, if the asynchronous flag is set to <code>false</code>, the request doesn&#8217;t run <q>in the background.</q>  Instead the script that is running waits for a response from the server before it continues.
</p>
<p>
 It just turns out XML is slightly more usable for complex stuff and that synchronous requests defeat the point.  Though <q><acronym title="Asynchronous JavaScript and Text">Ajat</acronym></q> have many uses.
</p>
<h3 id="sect1.4">DOM Scripting</h3>
<p>
 DOM scripting is the key to Ajax.  Ajax is pretty useless if you can&#8217;t extract the data.  Basically put, the DOM is HTML / XML represented in an object.  DOM Scripting, then, is using JavaScript (or some other language, I suppose) to manipulate this object.  If you manipulate the DOM of your HTML page, it will reflect visibly in the browser.
</p>
<p>
 DOM scripting replaces old-school <code>document.write</code> coding.  Instead, you insert nodes (<acronym title="Also Known As">aka</acronym> tags) or remove nodes from the DOM, and thus the page.  The great thing is that XML files can be represented as a DOM object.  That means that you can manipulate the XML the same way you manipulate the HTML.  You&#8217;ll make a lot of use of the following (where <code>xml = xml_obj.responseXML</code>):
</p>
<ul>
<li><code>xml.childNodes</code> is a collection of the children of the current node.  It&#8217;s handy to loop on: <code>for(i = 0; i < xml.childNodes.length; i++){}</code></li>
<li><code>xml.nodeName</code> is the string value of the current tag.</li>
<li><code>xml.nodeType</code> is a numeric representation of what kind of node the current element is, text (<samp>3</samp>) or element (<samp>1</samp>).  This is handy for conditionals: <code>if(xml.nodeType == 3){alert(xml.nodeValue);}</code></li>
<li><code>xml.nodeValue</code> is the string value of the current element if it is a text node.</li>
</ul>
<p>
 There are more useful properties and methods, but, for now, we're going to loop through output.  It isn't the most efficient method, but it is more agnostic than, say, <code>xml.getElementsByTagName</code>.
</p>
<h2 id="sect2">A Basic Ajax Chat</h2>
<p>
 As we see above, we already have a good deal of code written.  In fact, most of the tedious stuff is done.  We just have to solve a few problems.
</p>
<h3 id="sect2.1">Server Side Scripting</h3>
<p>
 Ajax isn't worth much without server side scripting.  <acronym title="PHP Hypertext Preprocessor">PHP</acronym> is my weapon of choice, but <acronym title="Active Server Pages">ASP</acronym>, Perl, Ruby, or any other language will work just fine.  However, since I chose PHP, it will affect my data storage solution.
</p>
<h3 id="sect2.2">Data Storage</h3>
<p>
 Most people use Ajax to deliver data stored on the server.  All the usual methods are available including mySQL, text files, and XML.  XML seems like the likely choice, since we are spitting out XML.  However, at least with PHP, working with XML is hard.  Further, doing queries on XML seems like it'd be severely difficult in PHP.  Other languages might like XML better than PHP, though.
</p>
<p>
 So, for the sake of this article, that leaves text files and mySQL.  Normally, I'd go with mySQL but this is a simple article. So, we're just going to use text files.  Opening files is easier than writing all the code to get the database running.
</p>
<h3 id="sect2.3">The Text Storage File</h3>
<p>
 The text file needs to only hold two variables: the name of the person sending the message, and their message.  We'll use a tab-separated file since it is unlikely that the user will enter a tab (because that typically changes fields) and we'll remove all carriage returns.  So, the XML file mentioned at the beginning before will be stored like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Fred	Fred here... Just making a post!
Joey	Hey, Fred.  Thanks for the post.</pre></div></div>

<h2 id="sect3">Convert The Text File To XML</h2>
<p>
 We'll need to write a function in PHP to convert the text file to XML for display in our chat application.  It should be something like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> tsv_to_xml<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>file_exists<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		$output <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>file_get_contents<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
		die<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Couldn't open the file.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$output <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
		$output <span style="color: #339933;">=</span> explode<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>$output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
		$output <span style="color: #339933;">=</span> array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$return <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;messages&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>$i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> $i<span style="color: #339933;">&lt;</span>count<span style="color: #009900;">&#40;</span>$output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> $i  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$output<span style="color: #009900;">&#91;</span>$i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> explode<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span>$output<span style="color: #009900;">&#91;</span>$i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;message&gt;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;from&gt;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span>.<span style="color: #660066;">htmlentities</span><span style="color: #009900;">&#40;</span>$output<span style="color: #009900;">&#91;</span>$i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;/from&gt;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;body&gt;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span>.<span style="color: #660066;">htmlentities</span><span style="color: #009900;">&#40;</span>$output<span style="color: #009900;">&#91;</span>$i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>.<span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;/body&gt;&quot;</span><span style="color: #339933;">;</span>
		$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;/message&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	$return .<span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;/messages&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> $return<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
 That should return the XML file specified at the beginning from the tab-separated file.
</p>
<h2 id="sect4">Adding a New Message</h2>
<p>
 We also need to add to the text file.  So, we'll write a PHP function for that, as well:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> tsv_add<span style="color: #009900;">&#40;</span>$file<span style="color: #339933;">,</span> $from<span style="color: #339933;">,</span> $body<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>file_exists<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		$output <span style="color: #339933;">=</span> trim<span style="color: #009900;">&#40;</span>file_get_contents<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">else</span>
		die<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Couldn't open the file.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$from <span style="color: #339933;">=</span> preg_replace<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/(<span style="color: #000099; font-weight: bold;">\s</span>|<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>|<span style="color: #000099; font-weight: bold;">\r</span>|<span style="color: #000099; font-weight: bold;">\n</span>)/&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">,</span>$from<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$body <span style="color: #339933;">=</span> preg_replace<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/(<span style="color: #000099; font-weight: bold;">\s</span>|<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>|<span style="color: #000099; font-weight: bold;">\r</span>|<span style="color: #000099; font-weight: bold;">\n</span>)/&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #339933;">,</span>$body<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$tsv <span style="color: #339933;">=</span> $from.<span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>.$body<span style="color: #339933;">;</span>
	$my_file <span style="color: #339933;">=</span> fopen<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;$file&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fwrite<span style="color: #009900;">&#40;</span>$my_file<span style="color: #339933;">,</span> trim<span style="color: #009900;">&#40;</span>$tsv<span style="color: #009900;">&#41;</span>.<span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>.$output<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	fclose<span style="color: #009900;">&#40;</span>$my_file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">return</span> tsv_to_xml<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
 Basically, we create a tab-separated entry for our file (stripping out protected characters), dump it into a file and return the updated XML file.
</p>
<h2 id="sect5">Putting the PHP Together</h2>
<p>
 It'd be a bummer to use several different PHP files when one would do.  So, we'll use a script to manage it.  We want to accept an <code>action</code> parameter to help our script decide what to do.  It will look like this:
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$file <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;./data/chat.txt&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>$_POST<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;action&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;get_xml&quot;</span><span style="color: #339933;">:</span>
		header<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		echo tsv_to_xml<span style="color: #009900;">&#40;</span>$file<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		die<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;add_post&quot;</span><span style="color: #339933;">:</span>
		header<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Content-type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		echo tsv_add<span style="color: #009900;">&#40;</span>$file<span style="color: #339933;">,</span> $_POST<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;from&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> $_POST<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;post&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		die<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
		die<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;There is no action associated with that call.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
 Once we have all that PHP in one file, it will be our request file.  So, we will call it <code>request.php</code> and put it on our development server putting the <code>tsv_add</code> and <code>tsv_to_xml</code> functions at the top.  Make sure the data folder is writable!  Make sure you put an empty <code>chat.txt</code> file in the data folder!
</p>
<h2 id="sect6">The HTML</h2>
<p>
 The only thing we don't have is the HTML file (and a little bit of JavaScript) we'll use to display the XML from the chat.  The code for the HTML should look something like this (except you'll probably want to put the <acronym title="Cascading Style Sheets">CSS</acronym> in a file and use the <code>link</code> tag):
</p>

<div class="wp_syntax"><div class="code"><pre class="htmlstrict" style="font-family:monospace;">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Ajax Chat&lt;/title&gt;
  &lt;style type=&quot;text/css&quot;&gt;
   label{display:block; width:100%;}
   input{display:block; width:100%;}
   input#submit{width:auto;}
  &lt;/style&gt;
  &lt;script type=&quot;text/javascript&quot; src=&quot;chat.js&quot;&gt;&lt;/script&gt;
 &lt;/head&gt;
 &lt;body onload=&quot;get_xml();&quot;&gt;
  &lt;form method=&quot;post&quot; action=&quot;#&quot; name=&quot;send_form&quot; id=&quot;send_form&quot; onsubmit=&quot;send_xml(); return false;&quot;&gt;
   &lt;p&gt;
    &lt;label for=&quot;uname&quot; accesskey=&quot;n&quot;&gt;Name&lt;/label&gt;
    &lt;input type=&quot;text&quot; id=&quot;uname&quot; name=&quot;uname&quot;&gt;
   &lt;/p&gt;
   &lt;p&gt;
    &lt;label for=&quot;mbody&quot; accesskey=&quot;m&quot;&gt;Message&lt;/label&gt;
    &lt;input type=&quot;text&quot; id=&quot;mbody&quot; name=&quot;mbody&quot;&gt;
   &lt;/p&gt;
   &lt;p&gt;
    &lt;input type=&quot;submit&quot; id=&quot;submit&quot; value=&quot;Send Message&quot; accesskey=&quot;s&quot;&gt;
   &lt;/p&gt;
  &lt;/form&gt;
  &lt;div id=&quot;chat_area&quot;&gt;Loading chat...&lt;/div&gt;
 &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<h2 id="sect7">The Rest of the JavaScript</h2>
<p>
 We need just a little bit more JavaScript.  The <code>get_xml()</code> function, the <code>send_xml()</code> function, and the <code>messagesRetrieved()</code> function (see above).
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> messagesRetrieved<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>xml_obj.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>xml_obj.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> xml_obj.<span style="color: #660066;">responseXML</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			xml <span style="color: #339933;">=</span> xml_obj.<span style="color: #660066;">responseXML</span><span style="color: #339933;">;</span>
			output <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> xml.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j <span style="color: #339933;">&lt;</span> xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nodeType</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> k<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> k <span style="color: #339933;">&lt;</span> xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> k<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;from&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
								output  <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;b&gt;&quot;</span> <span style="color: #339933;">+</span> xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/b&gt;: &quot;</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
							<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">nodeName</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
								output  <span style="color: #339933;">=</span> xml.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">firstChild</span>.<span style="color: #660066;">nodeValue</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;br&gt;&quot;</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
			document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;chat_area&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> output<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;There was a problem retrieving the XML data:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> xml_obj.<span style="color: #660066;">statusText</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> xml_obj.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> get_xml<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	loadXMLDoc<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;request.php&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;action=get_xml&quot;</span><span style="color: #339933;">,</span>messagesRetrieved<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;get_xml()&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">5000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> send_xml<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	u <span style="color: #339933;">=</span> document.<span style="color: #660066;">send_form</span>.<span style="color: #660066;">uname</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	b <span style="color: #339933;">=</span> document.<span style="color: #660066;">send_form</span>.<span style="color: #660066;">mbody</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	qs <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;action=add_post&amp;amp;from=&quot;</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>u<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&amp;amp;post=&quot;</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>b<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	loadXMLDoc<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;request.php&quot;</span><span style="color: #339933;">,</span>qs<span style="color: #339933;">,</span>messagesRetrieved<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>
 Put all the JavaScript (except the initial skeleton of <code>messagesRetrieved()</code>) into a file called <code>chat.js</code> and save it to the same folder as the HTML file and <code>request.php</code>.
</p>
<h2 id="sect8">Finishing Up</h2>
<p>
 Assuming everything is set up the way I set it up on my server, you should have a rudimentary Ajax chat.  Of course, there are some tweaks I highly suggest.  The first being adding <code>clip</code> and <code>overflow</code> to the <code>chat_area</code> div.  If done right, you can have a scrollable window much like an <code>iframe</code>.
</p>
<p>
 The second thing to do is modify the script so it keeps track of the time the posts were made.  Then the script could figure out which posts the user hasn't received and send only them.  This will cut down on bandwidth, which is important.  I let my first Ajax Chat run all day and I ended up doing three gigs of bandwidth.  That's a lot considering it was all text files.
</p>
<p>
 The third thing I would do is learn more about DOM scripting and get rid of those <code>for</code> loops in <code>messagesRetrieved()</code>.  While they are agnostic and easy to add message items to, they aren't pretty.
</p>
<h2 id="sect9">Disclaimer</h2>
<p>
 I wrote this code and tested it on Safari and Firefox on Mac.  It worked for me with those browsers.  It might not work for you and you may have to tweak it heavily.  I don't have time to support it.  The code is free and it is yours to use.  So, feel free to modify it and ask other people for help with it.  If you want to be nice, link back to this page if you get it working.
</p>
<p>
 Oh, and since this dynamically updates an area of the page, it probably isn't very accessible to screen readers.  Don't say I didn't warn you.
</p>
<h2 id="sect10">Source Code</h2>
<p>
 You can <a href="/wp-content/uploads/2009/01/simple_xmlchat.zip">download all the files</a> mentioned above in a zip file.  They are uncommented, but the code is clean enough that you should be able to figure out what is going on.</p>
]]></content:encoded>
			<wfw:commentRss>http://robertdot.org/2006/06/23/how-to-make-an-ajax-chat-room/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
