Writing XML

Purpose:

This exercise and the next will convert your Register to read and write XML documents. In this exercise our main focus will be on writing XML, but we will have a brief exercise in seeing the result of using a validated XML document.

To be well-formed, an XML document must always have balanced tags. This can be done by careful writing on a field-by-field basis, or by creating an XML Document as a whole, and then asking it to write itself out.

What to hand in:

Source code and output for all 5 DOM reading portions; source code and sample run for register DOM writing portion.

Please capture your homework in a single file for submission, in an easily reviewable order.

Problems:

DOM Reading

This exercise does not focus on integrating into our Register class, but does provide a sample focused on reading and extracting values and attributes from an XML Document using the document-object model (DOM) approach.

Use the sample code as the starting point for this exercise, and the provided XML file and XML schema (xsd) file.

Note that an XML schema file is provided for validation, and by editing the XML file, or by changing the options in the parser, you can choose to validate the file or not.

  1. Make the XML file well-formed but invalild. Document the error message you get when reading the file in with validation.

  2. Make the XML file non well formed. Document the error message you get when reading the file in with validation.

  3. Does reading the file in without validation make a difference in this case?

  4. Extract the value of the element InitialBalance

  5. List the attributes of the Bank element.

Register DOM writing

In this case, you decide between modifying the Write functions inside of each class (or add a parallel set of functions to each class) for writing XML, or whether you wish to create an external visitor to the register nodes, turning each of them into XML in printing a register.

The former case, each RegisterLine-derived class must be changed, but the register writing routine does not; in the latter case, no RegisterLine-derived class must be changed, but the register writing routine must be changed.

Notes:

This exercise should start with the XML schema (xsd file) from the Sample Solution.

You will want to reference W3C DOM information from the Resources tab (or www.w3c.org).

Evaluation criteria:

Provide XML reading capabilities for sample XML file

20%

Providing XML writing capabilities in the Register class

60%

Test run(s) to verify proper operation

20%