CSCI 5733
XML Application Development
Summer 2009
Homework #2
Due date: July 1, 2009
Because of the time constraint, this assignment is less real-world like. Instead, the assignments are designed to provide non-trivial SAX and DOM practices in relative short programs.
(1) Write a Java program, UniqueNamePathDepthSax.java, to output the maximum number of distinct element names in the paths of the input XML document. This is the maximum of the numbers of unique element names in all paths from the root elements to leaf element nodes (one with no child elements). For example,
running
java UniqueNamePathDepthSax UniqueNamePathDepthTest1.xml
where UniqueNamePathDepthTest1.xml is
<?xml version="1.0" ?>
<
a>
<b>
<c/>
</b>
<d>
<e/>
<f>
<g>
<h />
<d />
</g>
<i/>
</f>
</d>
<j />
<
/a>
output:
The maximum number of distinct element names in the paths in
UniqueNamePathDepthTest1.xml is 5.
Similarly, running
java UniqueNamePathDepthSax UniqueNamePathDepthTest2.xml
where UniqueNamePathDepthTest2.xml is
<?xml version="1.0" ?>
< a>
<b>
<c/>
</b>
<d>
<e/>
<f>
<g>
<f />
<d />
</g>
<i/>
</f>
</d>
<j />
< /a>
output:
The maximum number of distinct element names in the paths in
UniqueNamePathDepthTest1.xml is 4.
(2) This question provides an opportunity for you to practice recursion using Java's DOM. Repeat question (1), except using JAXP DOM this time. The program name should be UniqueNamePathDepthSax.java.
Turn in: