Code example for TransformerFactory

Methods: newTransformer

        private void validateDOMSource(DOMSource domSource, SAXParser parser, DefaultValidationErrorHandler errorHandler)
                throws IOException, SAXException { 
            try { 
                // Sadly, JAXP 1.0 DOM doesn't implement DOM level 3, so we cannot use Document.normalizeDocument() 
                // Instead, we write the Document to a Stream, and validate that 
                Transformer transformer = transformerFactory.newTransformer();
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                transformer.transform(domSource, new StreamResult(outputStream));
                ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
                validateStreamSource(new StreamSource(inputStream), parser, errorHandler);
            catch (TransformerException ex) {
                throw new XmlValidationException("Could not validate DOM source: " + ex.getMessage(), ex);
        private void validateStreamSource(StreamSource streamSource,
                                          SAXParser parser,
                                          DefaultValidationErrorHandler errorHandler) throws SAXException, IOException {