23.4. SAX Example 1: Printing the Outline of an XML Document

Listing 23.7 shows a content handler that responds to three parts of an XML document: start tags, end tags, and tag bodies. It overrides the startElement, endElement, and characters methods to accomplish this. The handler simply prints out the start element, end element, and first word of tag body, with two spaces of indentation for each nesting level. To accomplish this task, the content handler overrides the following three methods:

  • startElement This method prints a message indicating that it found the start tag for the element name. Any attributes associated with the element are listed in parentheses. The method also puts spaces in front of the printout, as specified by the indentation ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.