// Parse
InputSource inputSource =
new InputSource(new java.io.FileInputStream(
new java.io.File(xmlURI)));
reader.parse(inputSource);
As a result, you would get the following exception when running the
viewer:
C:\javaxml2\build>java javaxml2.SAXTreeViewer ..\ch03\xml\contents.xml
org.xml.sax.SAXParseException: File
"file:///C:/javaxml2/build/DTD/JavaXML.dtd" not found.
While this seems a little silly (wrapping a URI in a file and I/O
stream), it's actually quite common to see people using I/O
streams as input to parsers. Just be sure that you don't
reference any other files in the XML and that you set a system ID for
the XML stream (using the setSystemID( ) method on
InputSource). So the above code sample could be
"fixed" by changing it to the following:
// Parse
InputSource inputSource =
new InputSource(new java.io.FileInputStream(
new java.io.File(xmlURI)));
inputSource.setSystemID(xmlURI);
reader.parse(inputSource);
Always set a system ID. Sorry for the excessive detail; now you can
bore coworkers with your knowledge about SAX
InputSources.