DocumentBuilder.parse(InputStream) returns null

There is a good chance that the stream has been parsed correct, just because
xmlDoc.toString() will always be "[#document: null]". This doesn’t indicate, that the DOM tree is empty. Please check first, if the document has some nodes (children).

If the DOM really was empty, then I’d first print the content of the input stream to the console (maybe xmlSource.getInputStream().toString() already return the content) to check if the content is well-formed, double-check if the dtd file was accessible (browser) and finally, dump the XML document and the dtd into files to check if the XML content is valid.

Ahh, wait a second, I thought the second parameter was the URI of the DTD file, but the string is the systemId of the xml document (public StreamSource(InputStream inputStream, String systemId)). Maybe that’s a problem – the StreamSource class will use this URI to resolve relative URIs (like your DTD).

Leave a Comment