RSS

XML or JSON

One of the first tasks is to identify the datastore: XML or JSON.

The benefit to using XML is that I already have the entire list in XML. That has been my datastore for years. However, XML might be a bit heavy weight for this. JSON is more light weight and is less complicated for javascript to process as it is merely a representation of a javascript object.

Of course, if I am to use JSON, I have to convert my existing XML datastore. Let’s look at an XML example and a JSON example.

XML:

<PhoneNumber Prefix="555" Suffix="2368" Where="Ghostbusters" Who="Who You Gonna Call?"/>

JSON:
{"prefix":"555","suffix":"2368","where":"Ghostbusters","who":"Who You Gonna Call?"},

This is the extent of complexity of my datastore minus three fields not shown: type (tv or movie), contributor name, and contributor email. Counting characters, there is actually little difference: 85 characters for JSON versus 89 for XML. If I renamed PhoneNumber to PN or Num, XML would take up less space than JSON.

Processing, however, is significantly different for XML. At least so far as I have seen with jQuery.

The jQuery ajax function call is easily changed between handling xml and json:

var xmlResponse = $.ajax({
url: "numbers.xml",
dataType: "xml",

vs

var xmlResponse = $.ajax({
url: "numbers.js",
dataType: "json",

Handling the ajax return is much different.

XML processing:

success: function(xml) {
var numbers = new Array()
$(xml).find('PhoneNumber').each(function() {
var prefix  = $(this).attr('Prefix');
var suffix  = $(this).attr('Suffix');
var where   = $(this).attr('Where');
var who     = $(this).attr('Who');
var phoneNumber = new Object();
phoneNumber.prefix = prefix;
phoneNumber.suffix = suffix;
phoneNumber.where = where;
phoneNumber.who = who;
numbers.push(phoneNumber);
}
$.each(numbers, function(index, value) {
// some processing
}

JSON processing:

success: function(numbers) {
$.each(numbers, function(index, value) {
// some processing
}
}

Since JSON is the representation of a javascript object, I get that javascript object (here an array) back from jQuery’s .ajax call so I can just start using it. Now I could probably simplify the object creation within the function handling XML but, as a whole, it will never be as simple as the JSON version since I have to parse the XML and create my own array.

Down the road I want to add the ability to dynamically add numbers to the list. With a JSON data store, that is as simple as adding the number to the list and serializing the whole (JSON.stringify()). For XML, I believe that I would have to write the serialization code by hand or use different browser serializers and then define object to xml field mappings.

Based on all of this, I’ve decided to convert over to JSON for the datastore.

(Apologies for poor code formatting but that is what WordPress does.)

 
Leave a comment

Posted by on 2012/09/01 in Uncategorized

 
Aside

In order to guide these implementation attempts, the following is the list of basic requirements that I will rely on. These may change over time.

  • Display a table of all 555 numbers
    • Fields
      • Prefix (as some use letters JKL)
      • Suffix
      • Whose Number
      • Source (name of tv show, movie)
        • Nice to have: link to IMDb or Wikipedia
      • Type optional (IMDb and Wikipedia make this superfluous)
      • Contributor Name optional
  • The list will be loaded into the page dynamically
  • Filtering
    • The list will be filterable. Everybody wants to look up The Simpsons
    • Filter applies to multiple fields. Primarily Suffix, Whose number and Source
    • Filtering on Prefix
      • Preference: do not filter on this
        • Typing in 5, 55 or 555 will just return the whole list
      • Exception: If prefix contains non-numeric KLJ, etc
  • Move to new host
  • Allow numbers to be added through the website
    • Eventually. Dealing with spam and all the rest not high on the list

Requirements

 
Leave a comment

Posted by on 2012/09/01 in Uncategorized

 

JavaScript Libraries

This page is mainly for me to bookmark the JavaScript libraries that I am considering for use with my 555 website redesign project. They are a mix of Ajax and DHTML libraries so they may, technically, be considered distinct. However, my project has two aspects. (1) Load the list of 555 numbers and (2) provide search and display on the list. So I will need both types of library support.

jQuery

Prototype / script.aculo.us

Dojo

Ext JS

Now I need to define some requirements and pick a library for my first proof of concept.

 
Leave a comment

Posted by on 2012/07/31 in Uncategorized

 

Welcome to the 555-LIST Blog

A blog for the 555-LIST? Yes, a bit silly but I have a purpose.

I originally put the site together back in 1995 and, minus a few formatting changes, it has remained the same ever since. I thought it would be a good time to try out some changes to the site and blog about those.

In particular, I want to try a few different javascript libraries to put together a new interface focusing primarily on implementing searching of my “database” of numbers. I am also thinking about writing an iPhone/iPad app for the experience as well.

 
Leave a comment

Posted by on 2012/07/29 in Uncategorized

 
 
Follow

Get every new post delivered to your Inbox.