Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.

/** This application class accepts a source XML filename and uses SAX to parse the file. It echoes the contents with some modifications, restoring line breaks and a simple pattern of indenting child elements.

One major limitation: we gather character data for elements in a single buffer, so mixed-content documents will lose a lot of data! This works best with data-centric documents where elements either have single values or child elements, but not both. */publicclass XMLOutput { /** Builds a DOM document, checking that the DOM2 Traversal feature is supported before proceeding. Uses a < code > TreeWalker < /code > to pass through the source document, replacing the various SAX handlers from the previous version with a single loop that keeps element context as it goes. Writes the formatted output to a string buffer and from there to the console. */publicstaticvoid main ( String [ ] args ) { try { DocumentBuilder parser = DocumentBuilderFactory.newInstance ( ) .newDocumentBuilder ( ) ; if ( !parser.getDOMImplementation ( ) .hasFeature ( "Traversal", "2.0" ) ) { System.out.println ( "This application requires a DOM parser " + "that supports traversal." ) ; System.exit ( -1 ) ; }