Introduction to DOM
DOM, short form of Document Object Model, “is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents” (W3C 1).
DOM can represent a document (such as HTML or XML document) and can allow access to various elements of that document for examination and manipulation purposes. The standard DOM, standardized by the World Wide Web Consortium, uses a tree structure to represent any HTML or XML document, and provides a wide range of methods and properties to support critical tree operations, such as, navigation, examination, and modification. As a result, the standard DOM is implemented by most of the today’s well known browsers, such as, Netscape, Internet Explorer, Google Chrome, and etc (Flanagan).
The data of document, represented by tree nodes and entities, is defined in a logical structure by DOM. The structured format of a document provides great flexibility to enable developers to perform useful operations on the document’s data, such as addition, deletion, modification, and navigation. In DOM, the document has a tree structure with a root node, branches and leaves. The nodes in the document are defined as an interface objects that provides access to documents objects for manipulation. Some of the major nodes and node contents of XML document in DOM are: Document, DocumentType, Element, Attr, ProcessingInstruction, Comment, Text, and Entity (Chand).
There are currently four levels of specifications of DOM: DOM Level 0, DOM Level 1, DOM Level 2, and DOM Level 3. (Yang 1)
Operations Implemented
In this assignment, I have implemented the following operations:
Adding a new record
This operation allows the user to add a new record of either a book or an article. If the user wishes to add a book, then she must provide the title, first name and surname of all the authors (optional), name of the publisher, and the year of publication. In case if the user opts for adding an article, then she must provide the title, first name and surnames of all the authors (optional), name of the journal, an issue number, page number of beginning, page number of ending, and the year of publication.
Searching records
This operation allows the user to search for particular records. There are two options available to user; either to search records containing the search string in their titles, or to search records containing the search string in their any of the author’s surname. For example, if the user chooses the latter option and provides a search string ‘Moeller’, then all the records of books and articles that contains the search string ‘Moeller’ in any of their author’s surname will be retrieved.
Creating reports
This operation allows the user to create a report. The user may choose to generate a report in which the nodes are grouped either by type (book and article) or by author names.
Problems encountered
Although I had heard about Python many times, but I never got an opportunity to learn or work on this language before this assignment. Despite the fact that I have practical experience with popular programming language like C and Java, working on this assignment was not easy because the syntax of Python language is totally different from C and Java and is also too much confusing. To do this assignment, I was compelled to read tons of tutorials on Internet and books in library to learn Python which made this assignment even more challenging and time-consuming. As I was learning Python and working on this assignment in parallel, I was stuck at many points during implementing the program. Some of the major issues that I faced while working on this assignment were:
Unawareness with Python syntax
As already mentioned above, this was the most major problem for me in doing this assignment. Before starting to work on this assignment, I was under the impression that I would be able to complete the assignment without any problem as I have good knowledge of C and Java language. But as soon I started to work on this assignment, I realized that Python is considerably different from C and Java. Most of the keywords and operators that are available in C and Java were missing in Python. Also, the syntax of Python is not user-friendly. I was facing lot of problem in understanding the syntax and most of my valuable time was consumed in just learning the language.
Record searching
Adding a new record was not too hard because there is abundant of help available on Internet related to this subject. However, I had a very tough time in implementing the search operation especially due to the use of XPath expressions. Although XPath expressions are very powerful and provide flexible way to search or traverse the nodes in the document tree, writing the correct XPath expression is not an easy task.
Honestly speaking, implement this operation would not take too long if I would be using C or Java because the debugging is very easy in these language as the variables have strict data types. This is not the case with Python; it does not involve Data Types and the variable can store any type of data which makes debugging process very difficult because the developer then needs to check every method’s return value or evaluate the value stored in the variable on several occasions to know the exact type of an object.
Simple editor
I implemented the program in Python’s built-in editor, IDLE (Integrated Development Environment) version 2.6.6. This editor is pretty good for basic development purposes but it severely lacks strong debugging capabilities. Debugging the code is like a night mare in this editor – there is no menu for debugging. The user can only run the code but cannot debug to ensure the code’s accuracy.
Creating a report
The report for grouping the nodes by type was implemented too easily – just in 30 minutes. But the other report in which the nodes were to be grouped by author names was very tough. Honestly speaking, this report consumed lot of my time and energy, and at one moment I was so frustrated that I thought to quit and leave it as it is. The XPath expression was not easy and it took lot my time to write a correct XPath expression. After lot of efforts, I was soon able to write the correct XPath expression and I was happy thinking that soon I would be over with the coding. But I was wrong as the frustrating part was remaining.
At time of writing the contents to XML file, the nodes were not appearing under all the groups properly; means even if a particular book or article had several authors, the node representing that book or article was appearing only under one group which was not the desired output of course. I checked like hundreds of times that if the XPath expressions were returning the correct number of nodes, but to my surprise, there was no problem with the expressions and I could all the nodes under every group. But whenever I tried to write the contents of the node to the file, the contents were only appearing under one author.
I tried a lot to figure out the reason for the odd output but failed. Luckily when I was about to give up, I thought to give the final try and what I did was to create the copy of the node while writing to the file. Surprisingly, it worked. The solution that I applied as a chance worked and finally, all the desired operations were successfully implemented.
Works Cited
Chand, Mahesh. A programmer’s guide to ADO.NET in C#. New York: Apress, 2002. Print.
Flanagan, David. JavaScript: the definitive guide. California: O’Reilly Media, 2002. Print.
W3C. Document Object Model (DOM). 2005. Web.
Yang, Herong. Overview of DOM Specifications. Web.