SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Building Site Favorites with an XML Super Cookie
By Scott Isaacs

Storing user-data traditionally has been fairly complicated - you needed write code on the server for storing, retrieving, and applying the user data. Standard cookies offer minimal relief but are very limiting in the amount of data they can store. Internet Explorer 5.0 helps address this problem by allowing sites to store up to 640K of information per domain (split into any number of files up to 64K each). These files are XML files and and are more easily manipulated than standard cookies using the XML Document Object Model.

In this article, we demonstrate a simple use of the XML persistance format to create a site favorite list. The site favorite list lets users add pages to a site-specific favorite list plus a simple mechanism for retrieving and viewing the list. This favorite list has no relationsihp to browser-based favorites but rather is a targeted list of bookmarks associated with a particular web-site that the user wants to remember.

To enable the XML persistance you need to apply the IE5 user data behavior to an element in your document. For favorites, we chose to apply the behavior to a custom element. To define custom elements, you must first specify the name space for the element. The name space is used to define the context for a set of elements. For example, all HTML elements belong to an implicit HTML name space. For our favorite list, we create a SITEINFO name space. The name space is declared on the HTML element as follows:

<HTML XMLNS:SITEINFO>

We can now use elements within the SITEINFO name space. We use a single element named "FAVORITES". To use an element in the SITEINFO name space you must specify both the name space and the element name. We define the FAVORITES element as follows:

<SITEINFO:FAVORITES ID="siteFavorites"/>

Notice that we ended the tag with a "/>". All custom elements must be specified using XML. The "/" defines that the element is an empty element meaning no end tag (eg., </SITEINFO:FAVORITES>) is necessary.

The last step is to associate the user data behavior with the custom element. In IE5, behaviors are associated with elements using CSS and the IE5 behavior attribute. Below we add the user data behavior to the FAVORITES element:

<STYLE>
  SITEINFO\:FAVORITES {behavior:url('#default#userData')"}
</STYLE>

Before we go into the script, let's explain the simple schema we use to store the URL and a TITLE for each favorite. We are creating a very simple XML document. Underneath the document root we create a SITEINFO block that contains both a URL and a TITLE element. Each site in the favorites list has its own SITEINFO block. For example:

<ROOTSTUB>
 <SITEINFO>
  <URL>http://www.siteexperts.com</URL>
  <TITLE>SiteExperts.com Home Page</TITLE>
 </SITEINFO>
</ROOTSTUB>

Next we explain the script used to manipulate the favorites file.

Page 1:Building Site Favorites with an XML Super Cookie
Page 2:Scripting the XML User Data