SSC 1, 2010/2011 - XML Exercise

The XML exercise consists in using two different parsers for XML: StAX and DOM. You need to create two different programs and use them to display an arbitrary XML file using the format explained below.

For example, given an XML file with the following structure:

<root>
<node1>Text1</node1>
<node2>Text2</node2>
<node3>
        <node4>
                <node5>Text4</node5>
        </node4>
</node3>
<node6>
        <node7>Text5</node7>
        <node8>Test6</node8>
</node6>
</root>

You need to create two different programs, one using DOM and the other using StAX so that they display the example XML structure above, to standard output by using the following output format:

Node: root
|	Node: node1
|	|	Data: Text1
|	Node: node2
|	|	Data: Text2
|	Node: node3
|	|	Node: node4
|	|	|	Node: node5
|	|	|	|	Data: Text4
|	Node: node6
|	|	Node: node7
|	|	|	Data: Text5
|	|	Node: node8
|	|	|	Data: Test6

Please note that your programs should work for any XML file provided and not just the example given above. The output format above displays the content of the XML file by imitating a tree structure allowing us to trace the children and the parents of all the nodes in the tree.

Sample implementation ideas

In order to do this exercise, it is highly suggested that you use recursion to print out the nodes. Here are a few brief hints on how to do that: