B.6. Chapter 11 Exercise

The task with this exercise was to take the XML from Listing B-9, parse it, and insert it into a new SQLite database. Thus you'll need to do two things to accomplish this task. First, you'll need to create the code needed to create a new database and table to hold the month data. Second, you'll need to load the XML, parse it, and insert it into the new database.

Take a look at the solution file in Listing B-10. You will see that the init() function that is called on creationComplete makes a call to the openOrCreateDatabase() function. This function will either open the database if it already exists or create the database file, which will then call the createTable() function. The createTable() function will create the Months table with five fields needed to hold a unique identifier, the SortOrder, and the English, Spanish, and Italian translations.

The Months.xml file will be loaded using an HTTPService. The button labeled "Save XML to database" will load in the Months.xml file by calling the send() method on the HTTPService when it is clicked. The onLoad() function is called after the Months.xml file is loaded. This function parses the XML, loops through the months, and calls the insertMonth() function on each iteration of the loop. The insertMonth() function accepts the XMLNode, parses out each property, and inserts them into the Months database table. The results can be seen in Figures B-8 and B-9.

Example B-9. The Months.xml file
<?xml version="1.0" ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.