2008-11-15

Document is null

I tried to read an XML configuration file into a DOM, like so:

InputStream configInputStream = this.getClass().getClassLoader().getResourceAsStream(CONF_FILE_NAME);
log("configInputStream = " + configInputStream);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(configInputStream);
log("Found and read configuration: " + doc);
configInputStream.close();

...and the log said:
INFO: ToonGrator: Found and read configuration: [#document: null]

I guess the square brackets and the extra text should have tipped me off, but I sure thought
I had read in a null document!

It isn't really. It turns out that the root (or document) node always contains no text, so
whatever its toString() returns will say "null". Oh well, back to work!

No comments: