Java Reference
In-Depth Information
When the above search request is sent to the web server, it will respond with the follow-
ing response:
<result>
<state>
<code>MS</code>
<name>Mississippi</name>
</state>
<state>
<code>MO</code>
<name>Missouri</name>
</state>
</result>
Once you have decided on a state that you would like displayed and click it, the following
request will be sent:
<request type="state">
<code>MO</code>
</request>
The above request asks for information about the state of Missouri. The web server will
respond as follows:
<result>
<state id="25">
<code>MO</code>
<name>Missouri</name>
<capital>Jefferson City</capital>
<url>http://www.state.mo.us/</url>
</state>
</result>
The above response is used by the JavaScript to display information about Missouri.
Writing a Bot for the XML AJAX Site
We will now create a bot that can download and process the XML data from the AJAX web
site. This recipe is shown in Listing 10.2.
Listing 10.2: XML AJAX Bot (AjaxXML.java)
package com.heatonresearch.httprecipes.ch10.recipe2;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.SAXException;
Search WWH ::




Custom Search