Java Reference
In-Depth Information
Once you get a cookie, you should break it into its session ID and domain parts,
which you can do by cracking the cookie string at its semicolon; this splits the two parts.
A good place to store the resulting session is in a member field of the Java class imple-
menting your web service client. You'll then check the domain against subsequent URLs
you request, sending the cookie only if the domains match using the HttpConnection 's
setRequestProperty , as shown in Listing 13-3.
Listing 13-3. Sending a Cookie with an HTTP Request
HttpConnection hc = (HttpConnection)Connector.open(url);
hc.setRequestProperty("cookie", mSession);
You may want to store cookies elsewhere, such as the record store, but there's a
catch: they expire, and when they expire depends on how the server is configured. If
you want to persist cookies, you should definitely parse the cookie for the expiration
date and handle expirations appropriately by removing them from your application's
store when they expire.
Using XML for Data Representation
XML provides a standard syntax for creating custom markup languages that let
you describe the data within a document. Derived from the Standard Generalized
Markup Language (SGML), it's one of the most widely used markup languages
today. In this section, I give you just a thumbnail sketch of XML, the nitty-gritty
you need to understand to use simple XML in your own applications. For a thorough
introduction to XML, I encourage you to visit the W3C documentation at http://www.
w3c.org/XML .
XML syntax provides you with a general syntax for representing document
trees that originate with a single root element that must contain zero or more child
elements, which themselves can have children. Elements consist of tags that have
attributes and may contain other tags or data, like the example of a weather report
shown in Listing 13-4.
 
Search WWH ::




Custom Search