Displaying an Entire Document

In this next example, as in the previous chapter, I'm going to write a program that parses and displays an entire document, indenting each element, processing instruction, and so on, as well as displaying attributes and their values. Here, however, I'll use SAX methods, not DOM methods. If you pass ch12_01.xml to this program, which I'll call ch12_03.java, that program will display the whole document properly indented.

I start by letting the user specify what document to parse and parsing that document. To actually parse the document, I'll create an object of the current class and call that object's displayDocument method from the main method, as before. The displayDocument method will fill the array displayStrings ...

Get Real World XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.