CS 242 Spring 2012 : Assignment 2.0
CS 242 Spring 2012 : Assignment 2.0
This page last changed on Mar 06, 2012 by cemeyer2.
Code Complete Chapter 6: Working Classes
W3Schools.com XML Tutorial
For this assignment, you should work with your cpanel account. Each of you should have accounts by now. If you do not have access, please email the course staff ASAP. Instructions on what services are available as well as how to access them are located at https://wiki.engr.illinois.edu/display/engineeringit/Web+Hosting+for+Student+Projects. We will only be using the basic PHP functions this week, but in future weeks we will use more.
Your task for this week is to take raw XML files representing your work so far this semester and transform it into a nicely formatted XML document that we will transform to HTML next week.
You are free to design the look of your own portfolio however you like. We will use XSLT next week to generate the actual HTML to display. However, XSLT is not good for making large changes in structure – with XSLT, the generated HTML largely follows the structure of the XML. This week, you need to take the XML from subversion and convert it to an XML structure that better represents how you want the portfolio to look. So you need to think about the layout you want and choose the XML structure based on that. We give an example below. (In future weeks, we will have you add a commenting feature, so in designing your layout you should keep that in mind, even though it won’t be included just yet.)
You will need to get access to a machine that has the svn command line program on it. The EWS linux machines have it already installed. To get the raw data, enter the following command:
This will save the log and listing of your repository into a file called “svn_log.xml” and “svn_list”. You will need to transfer these files to somewhere readable on your cpanel account. See the svn log documentation or run the command svn help log to get more details on the svn log command. See similar pages for svn list help.
The format of the file is something like:
SVN log output:
SVN list output:
Your job for this week is to read in that data, parse it with the PHP XML parser that you customize, then output it as a new XML file. It is up to you to determine the format of the new XML file, but here is one suggestion:
Here is a brief description of this particular XML output. You are free to come up with whatever output you wish, but it must have all of the basic information we have here.
You need to parse the raw data and transform it into this type of format. You will need to account for the differences in the file structures and write your code accordingly. It is up to you to decide from which of the two input files you want to take each of the pieces of data from (there is some overlap). Feel free to go above and beyond and add more information from the input files into your output. We are transforming these two input XML documents into one in order to provide an easier input into next week’s assignment where we will be displaying the results graphically using an XSLT transform.
We want you to write in an Object-Oriented fashion this week. That is, you should have classes representing all of your basic data objects (one for a project, one for a revision, one for a file, etc), one for your parser, one for your output engine, etc. You can use the built-in XML processor that expat PHP provides or SimpleXML as the basis for your parser object. Here is an example of the constructor and a parse function for an object that parses one XML (yours will need to parse two XML files) using expat:
We then create functions named tag_open, tag_close, and cdata which the parser calls on each part of the document tree as it parses. For instance:
We ask you to encapsulate your parser in an object because it will probably need to maintain state as it parses and builds up a data structure.
Once you have the data structure built up in memory, you will need to output the xml back to the user. You should look up the PHP documentation for DOMDocument. Build on a DOMDocument object from your data structure and then call ->saveXML() on it to produce nice results. You can echo this text back to the user.
Your main PHP file that the user loads up in their browser to get the formatted XML back might be something like:
This assignment is particularly tricky to test using unit tests, so for this week we encourage you to write more integration style tests. You should be able to construct several small input XML files by hand and verify that your code produces the proper data structure in memory, then outputs the proper converted XML back to the user. You should test for all possible corner cases you can think of, such as:
|Document generated by Confluence on Mar 29, 2012 02:55|