
XML and Java • 351
We discuss this example now.
Exercise 3: For the following XML document, compute the total price of all the CDs.
<?xml version=”1.0”?>
<catalog>
<cd>
<title>Raga Todi</title>
<artist>Kishori Amonkar</artist>
<country>India</country>
<company>HMV</company>
<price>250</price>
<year>2001</year>
</cd>
<cd>
<title>Beguna Guna Gaiye</title>
<artist>Bhimsen Joshi</artist>
<country>India</country>
<company>Times Music</company>
<price>300</price>
<year>1999</year>
</cd>
</catalog>
Solution 3:
import java.io.IOException;
import java.lang.*;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes; ...