COMP249 Web Technology
Practical - Week 10
The aim of this practical session is to explore XML.
XML Basics
XML is a meta-markup language that was designed to describe data. XML allows authors to define their own tag set and their own document structure. Work throught the basic part of W3School's XML tutorial and then answer all the questions in the following XML quiz. (Note: The final COMP249 exam will have a similar multiple choice section about various topics).
Parsing via XML DOM
Study Section 8.7 of the Python Library Reference which introduces a lightweigth XML DOM implementation for Python, then take the following Python skeleton as a starting point:
from xml.dom import minidom
xmldoc = minidom.parse('books.xml')
for node in xmldoc.getElementsByTagName('...'):
...
and flesh it out, so that you can extract the subsequent information:
- all book nodes
- the first book node
- the text of all price nodes
- all price nodes with prices higher than 40.
from a the XML document books.xml.
Parsing XML in Javascript
The file javascript-dom.html contains some example javascript to parse the books.xml file and insert some data into the HTML page from the file. Extend this to get some data about each book (authors, price) and insert it in the output.
Portfolio
Either of the examples above could form the starting point of a portfolio item showing off some XML parsing techniques. The second example is the beginning of a simple AJAX application (although not strictly AJAX since it doesn't use XMLHttpRequest and just gets a static file). Try generating the XML file in a CGI script and parsing it in Javscript in a page to experiment with more dynamic content.