Sunday, June 01, 2008

My Thesis - Literature Study - kXML

Both database backup and recovery will use XML technology. The resulting backup-files and the recovery files will be stored in XML format. In order to implement this scheme, a XML parser will be needed. There are three kinds of XML Parser:
  • Model parser
    • It reads an entire document and creates a representation of the document in memory. Model parsers use significantly more memory than other types of parsers.
  • Push parser
    • It reads through an entire document. As it encounters various parts of the document, it notifies a listener object.
  • Pull parser
    • It reads a little bit of a document at once. The application drives the parser through the document by repeatedly request the next piece.

Among these three parser types, pull parser is considered to be the best choice since it could support the ability to parse huge size of XML file (i.e. typical size of database backup result). kXML [1] is an example of XML pull parser. It is an open source and free XML parser. It is also small in term of size (i.e. 50 kB, but if the application is obfuscated, the size can reduce to only 10 kB), so it will not really affect the size of the resulting application. Overall, the main advantages of using kXML are because kXML provides:
  • Simple to use API that concentrates on how to generate XML file quickly
  • Interface that is designed to allow implementation of very fast XML serializer
  • Minimal memory requirement
In order to parse a XML file, one must connect to the XML file (i.e. by employing JSR-75) and assign a file reader using InputStreamReader classes. Then, the file reader could be used to read and parse the XML file by using the KXmlParser.setInput() method. Moving through every tags using KXmlParser.nextTag() method, reading intended tag using KXmlParser.require() method, and reading tag’s content using KXmlParser.nextText() method.
When it comes to XML file-creation, KXmlSerializer class can be used to write through the content. KXmlSerializer provide method for:
  • Assigning output using the setOutput() method.
  • Identifying start of XML document using startDocument() method.
  • Writing tags using startTag() and endTag() method.
  • Inserting content into tags using text() method.
  • Finalizing the newly-created XML document using endDocument() method.
Another reason of using XML file is because one can create this file easily in PC. So, if the user hates the struggle of typing news content on his/ her mobile phone, the user can use notepad or other text editor application in his/ her PC to create the XML file with the news in it. After creating the XML file, the user can transfer it to his/ her mobile phone, and then use the database recovery feature to add the news inside the XML file into the news database.

[1] KXML.

No comments: