Displaying an Entire Document

In this next example, I'm going to write a program that will parse and display an entire document, indenting each element, processing instruction, and so on, as well as displaying attributes and their values. For example, if you pass ch11_01.xml to this program, which I'll call ch11_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 as before. To actually parse the document, I'll call a new method, displayDocument, from the main method:

public static void main(String args[]) 
{
    displayDocument(args[0]);
    .
    .
    .
}

In the displayDocument method, I'll parse the document and get an object corresponding to that document: ...

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.