How to prevent XML parsing errors being written to System.err (stderr)?
问题 I am writing some unit tests that are deliberately passing bad strings to the Java DOM XML parser. E.g. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); String message_xml = ""; // Empty string, not valid XML!!! ByteArrayInputStream input = new ByteArrayInputStream(message_xml.getBytes()); Document doc = db.parse(input); This is correctly throwing a SAXParseException (which is what my unit test expects). But it is also writing a