In this laboratory exercise you will replicate the process of building a program to process XML files using the SAX parser which we learned in class. Specifically we will be parsing an XML file related to a media library and using the contents of the file to build instances of three classes – Artist, Album, and Song.
Initial Project Setup
Inside your csc241 folder, create a new folder called lab3. Inside that folder put the appropriate files required for building the project using Gradle (i.e., a build.gradle file copied from a previous lab, and src/main/java folders).
Download the starter .java files from this directory on the web and place them in your project’s src/main/java folder.
Back in your lab3 folder, build the project using Gradle. It should compile without errors or warnings.
Download the library.xml file from the above directory on the web to your project’s build/classes/java/main folder.
Examine the starter classes for Artist, Album and Song, as well as the XML file library.xml. Your task will be to read an XML file in this format, and, using it, populate instances of these classes. Notice how the classes are connected – an Artist instance can have one or more Albums added to it, and an Album can have one or more Songs added to it.
A starter XML parser has been provided in LibraryXMLParser.java. Add to this an ArrayList to contain all of the Artists in the library, and add a method to print out the contents of the library (by printing each Artist; toString methods have been provided in each class).
Using the techniques learned in class, parse the XML file and populate the required classes. After the parse is complete, call your method to print the contents of the library.
Once you’ve finished the lab, show your lab TA and they will mark you off as having finished.