[Previous] [Contents]


Exercises


1. For use in Omnimark, write the rule header for catching:
The element named note
The element tool that is a grandchild of the element procedure
The element result, which comes after action
The element listitem, which comes first in a sequence of listitems but isn't the first element in its parent
2. For SAX, write an event handler that outputs the following report taking the file musicians.xml as input:
1:  Start document
2:  Start element: musicians
3:  Start element: musician
4:  Start element: name
5:  Characters: Joey Baron
6:  End element: name
7:  Start element: instrument
8:  Characters: drums
9:  End element: instrument
10:  Start element: NrOfRecordings
11:  Characters: 1
12:  End element: NrOfRecordings
13:  End element: musician
14:  ...
15:  End element: musicians
16:  End document

You can use the following template:
1:  import org.xml.sax.HandlerBase;
2:  import org.xml.sax.AttributeList;
3:
4:  public class YourHandler extends HandlerBase {
5:
6:       public void startDocument ()
7:             {
8:                      System.out.println("XXXXX");
9:             }
10:
11:      public void endDocument ()
12:            {
13:                     System.out.println("XXXXX");
14:            }
15:
16:      public void startElement (String name, AttributeList atts)
17:            {
18:                     System.out.println("XXXXX");
19:            }
20:
21:      public void endElement (String name)
22:            {
23:                     System.out.println("XXXXX");
24:            }
25:
26:      public void characters (char ch[], int start, int length)
27:            {
28:                     System.out.println("XXXXX");
29:            }
30:  }



[Previous] [Contents]