Even though this lab does not involve any programming, it does have an important and fundamental objective, that is, to ensure you understand completely what the value of an XMLTree object looks like. Please make sure you answer each of the questions in this lab carefully and thoughtfully. Discuss them with the classmate sitting next to you and write down all the answers so that an instructor can check them out. If you encounter any problems or you have any doubts about any of the questions, please make sure you ask an instructor for help.
The XMLTree family of components provides convenient functionality to read and process XML documents. Understanding the model of an XMLTree is essential to being able to use these components. This lab activity will take you step-by-step through the concepts needed to understand the model. In the next lab you will learn and practice how to manipulate XMLTrees with the methods provided by the XMLTree component.
Carefully consider and answer the questions below.
Given the tree of colors below, answer the following questions.
Consider the following XML document and answer the questions below.
Now consider the following XML document and answer the questions below.
Here is a picture of an XMLTree representing the second XML document above.
Recall that in an XMLTree the children of a given node are numbered with increasing integer values (indices, positions) starting at 0 for the first child, 1 for the second child, etc. For instance, in the XMLTree above, <title> is child 0 of <album>, <composer> is child 1, <conductor> is child 2, and so on.
A path in an XMLTree can be identified in two different ways by either listing the labels of the nodes on the path or by listing the index of each node (except the root) as a child of its parent. So, for instance, a path from the root to the George Gershwin node can be identified either by listing the nodes on the path: (<album>, <composer>, George Gershwin), or by listing the root followed by the indices corresponding to the nodes on the path: (<album>, 1, 0) because <composer> is child 1 of <album> and George Gershwin is child 0 of <composer>.
Consider the text node An American in Paris in the XML tree above.
Suppose we modified the XML document above so that both the <composer> and the <conductor> tags have an attribute born whose value is the date of birth, i.e.,
Now suppose we wanted to change the <released> tag in the XML document above so that the date is not an attribute of the tag but instead a text child of the tag node.
Consider the following XML document:
For this part of the lab, you will use a program that allows the user to load XML documents into XMLTree objects and display their values. You can run this program by importing it into Eclipse. First you need to download the project archive, xmltree-viewer.zip, to your computer. Click on this download link and save the file somewhere on your hard drive where you can easily find it. Make sure that you do not expand this archive. If your browser automatically expands downloaded zip archives, that's OK too. Just pay attention to the special instructions in the following few steps. You may want to make a note of where you saved it.
Import your new project in Eclipse by following these steps:
To run the program, find the RunViewer.java file in the src folder in the project and run it as usual as a Java Application.
Once you start the program, you can enter the URL of an XML document or a path on the local drive for an XML file in the XML Input field and click Go to load an XML document, open a new window, and display the value of the corresponding XMLTree. There are several ways to enter your input in the field: you can type the URL or file path, or you can use the Browse... button to locate a file on the local drive, or you can select one of the entries you have used before (if any) in the drop-down menu.
Copy and paste (or type) the entry http://web.cse.ohio-state.edu/software/2221/web-sw1/extras/instructions/xmltree-model/album.xml in the address bar and click Go. This XML document contains the XML example we used earlier. Expand all the nodes and see how the tree displayed in the viewer window matches with the XMLTree picture above.
In particular, observe the different icons used to identify tags and text nodes; also note how attributes and their values are displayed between []. Make sure you do not continue until you can match each element in the XMLTree above to each element of the XMLTree displayed in the viewer.
Now let's open a page downloaded from Yahoo's weather forecast XML service. Copy and paste (or type) the entry http://web.cse.ohio-state.edu/software/2221/web-sw1/extras/instructions/xmltree-model/columbus-weather.xml in the address bar and click Go.
Answer the following questions by exploring the XMLTree displayed.