|
The input for this program is the file
casablanca.xml
We are initially interested in the element:
<director>Michael Curtiz</director>
-
Observe that the program prints the director of the movie.
-
Change the program so that it outputs the title of the movie
followed by the year in brackets. Casablanca (1944)
Note that this data is held in a node:
<title year="1942">Casablanca</title>
-
You will need to create a global variable to store the year
every time you start an element with name title.
yr = atts.getValue("year"); - yr must be declared
outside the method.
-
Change the printOn so it is set for
title elements
rather than director elements.
-
Change the println to include the title. System.out.println((new String
(t,s,l)) + "(" + yr + ")");
-
Change the program so that is prints the name of the actor
playing "Victor Laszlo".
-
We can rely on the fact that the text node that comes before
"Victor Laszlo" will be the name of the actor playing that part.
All we need do is record the "previous" text node.:
if ("Victor Laszlo".equals(new String(t,s,l)))
System.out.println(prevText);
prevText = new String(t,s,l);
prevText must be declared outside the method.
-
The previous example was fixed! The casablance.xml file has no
redundant white space in it. The file casablanca2.xml does have
redundant white space (as is common in XML documents). Change
class S so that loads
casablanca2.xml
Does it still work?
|
|