javax.xml.transform.dom.DOMResult Java Examples
The following examples show how to use
javax.xml.transform.dom.DOMResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Parameter.java From iaf with Apache License 2.0 | 6 votes |
private Object transform(Source xmlSource, ParameterValueList pvl) throws ParameterException, TransformerException, IOException { TransformerPool pool = getTransformerPool(); if (TYPE_NODE.equals(getType()) || TYPE_DOMDOC.equals(getType())) { DOMResult transformResult = new DOMResult(); pool.transform(xmlSource,transformResult, pvl); Node result=transformResult.getNode(); if (result!=null && TYPE_NODE.equals(getType())) { result=result.getFirstChild(); } if (log.isDebugEnabled()) { if (result!=null) log.debug("Returning Node result ["+result.getClass().getName()+"]["+result+"]: "+ ToStringBuilder.reflectionToString(result)); } return result; } return pool.transform(xmlSource, pvl); }
Example #2
Source File: MathMLDownConverter.java From symja_android_library with GNU General Public License v3.0 | 6 votes |
public Document downConvertDOM(Document document) { /* If inlining CSS, create a document to hold the name/value pairs as described in * buildCSSPropertiesDocument(). Otherwise, we'll create an empty one to indicate * that nothing should be inlined */ Document cssPropertiesDocument = XMLUtilities.createNSAwareDocumentBuilder().newDocument(); if (cssProperties!=null) { buildCSSPropertiesDocument(cssPropertiesDocument, cssProperties); } /* Create URI Resolver to let the XSLT get at this document */ CSSPropertiesURIResolver uriResolver = new CSSPropertiesURIResolver(cssPropertiesDocument); /* Run the conversion XSLT */ Templates templates = stylesheetManager.getStylesheet(Globals.MATHML_TO_XHTML_XSL_RESOURCE_NAME); Document result = XMLUtilities.createNSAwareDocumentBuilder().newDocument(); try { Transformer transformer = templates.newTransformer(); transformer.setURIResolver(uriResolver); transformer.transform(new DOMSource(document), new DOMResult(result)); } catch (Exception e) { throw new SnuggleRuntimeException("Unexpected Exception down-converting DOM", e); } return result; }
Example #3
Source File: AbstractSchemaValidationTube.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private Document createDOM(SDDocument doc) { // Get infoset ByteArrayBuffer bab = new ByteArrayBuffer(); try { doc.writeTo(null, resolver, bab); } catch (IOException ioe) { throw new WebServiceException(ioe); } // Convert infoset to DOM Transformer trans = XmlUtil.newTransformer(); Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm()); DOMResult result = new DOMResult(); try { trans.transform(source, result); } catch(TransformerException te) { throw new WebServiceException(te); } return (Document)result.getNode(); }
Example #4
Source File: TransformerUtil.java From keycloak with Apache License 2.0 | 6 votes |
/** * Use the transformer to transform * * @param transformer * @param source * @param result * * @throws ParsingException */ public static void transform(Transformer transformer, Source source, DOMResult result) throws ParsingException { boolean tccl_jaxp = SystemPropertiesUtil.getSystemProperty(GeneralConstants.TCCL_JAXP, "false").equalsIgnoreCase("true"); ClassLoader prevCL = SecurityActions.getTCCL(); try { if (tccl_jaxp) { SecurityActions.setTCCL(TransformerUtil.class.getClassLoader()); } transformer.transform(source, result); } catch (TransformerException e) { throw logger.parserError(e); } finally { if (tccl_jaxp) { SecurityActions.setTCCL(prevCL); } } }
Example #5
Source File: XMLOutputFactoryImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public javax.xml.stream.XMLStreamWriter createXMLStreamWriter(javax.xml.transform.Result result) throws javax.xml.stream.XMLStreamException { if (result instanceof StreamResult) { return createXMLStreamWriter((StreamResult) result, null); } else if (result instanceof DOMResult) { return new XMLDOMWriterImpl((DOMResult) result); } else if (result instanceof StAXResult) { if (((StAXResult) result).getXMLStreamWriter() != null) { return ((StAXResult) result).getXMLStreamWriter(); } else { throw new java.lang.UnsupportedOperationException("Result of type " + result + " is not supported"); } } else { if (result.getSystemId() !=null) { //this is not correct impl of SAXResult. Keep it for now for compatibility return createXMLStreamWriter(new StreamResult(result.getSystemId())); } else { throw new java.lang.UnsupportedOperationException("Result of type " + result + " is not supported. " + "Supported result types are: DOMResult, StAXResult and StreamResult."); } } }
Example #6
Source File: XMLDOMWriterImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Creates a new instance of XMLDOMwriterImpl * @param result DOMResult object @javax.xml.transform.dom.DOMResult */ public XMLDOMWriterImpl(DOMResult result) { node = result.getNode(); if( node.getNodeType() == Node.DOCUMENT_NODE){ ownerDoc = (Document)node; currentNode = ownerDoc; }else{ ownerDoc = node.getOwnerDocument(); currentNode = node; } getDLThreeMethods(); stringBuffer = new StringBuffer(); needContextPop = new boolean[resizeValue]; namespaceContext = new NamespaceSupport(); }
Example #7
Source File: XMLOutputFactoryImpl.java From Bytecoder with Apache License 2.0 | 6 votes |
public XMLStreamWriter createXMLStreamWriter(Result result) throws XMLStreamException { if (result instanceof StreamResult) { return createXMLStreamWriter((StreamResult) result, null); } else if (result instanceof DOMResult) { return new XMLDOMWriterImpl((DOMResult) result); } else if (result instanceof StAXResult) { if (((StAXResult) result).getXMLStreamWriter() != null) { return ((StAXResult) result).getXMLStreamWriter(); } else { throw new UnsupportedOperationException( "Result of type " + result + " is not supported"); } } else if (result.getSystemId() != null) { //this is not correct impl of SAXResult. Keep it for now for compatibility return createXMLStreamWriter(new StreamResult(result.getSystemId())); } else { throw new UnsupportedOperationException( "Result of type " + result + " is not supported. Supported result " + "types are: DOMResult, StAXResult and StreamResult."); } }
Example #8
Source File: StreamHeader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void writeTo(SOAPMessage saaj) throws SOAPException { try { // TODO what about in-scope namespaces // Not very efficient consider implementing a stream buffer // processor that produces a DOM node from the buffer. TransformerFactory tf = XmlUtil.newTransformerFactory(); Transformer t = tf.newTransformer(); XMLStreamBufferSource source = new XMLStreamBufferSource(_mark); DOMResult result = new DOMResult(); t.transform(source, result); Node d = result.getNode(); if(d.getNodeType() == Node.DOCUMENT_NODE) d = d.getFirstChild(); SOAPHeader header = saaj.getSOAPHeader(); if(header == null) header = saaj.getSOAPPart().getEnvelope().addHeader(); Node node = header.getOwnerDocument().importNode(d, true); header.appendChild(node); } catch (Exception e) { throw new SOAPException(e); } }
Example #9
Source File: BaseXmlMetaBuilder.java From geoportal-server-harvester with Apache License 2.0 | 6 votes |
@Override public Document create(MapAttribute wellKnowsAttributes) throws MetaException { try { Document inputDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Document outputDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Transformer transformer = xsltEncodeDC.newTransformer(); Properties props = AttributeUtils.toProperties(wellKnowsAttributes); props.keySet().stream().map(Object::toString).forEach((String key) -> { transformer.setParameter(key, props.getProperty(key)); }); Result result = new DOMResult(outputDoc); transformer.transform(new DOMSource(inputDoc), result); return outputDoc; } catch (ParserConfigurationException | TransformerException ex) { throw new MetaException(String.format("Error creating document."), ex); } }
Example #10
Source File: XMLDOMWriterImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Creates a new instance of XMLDOMwriterImpl * @param result DOMResult object @javax.xml.transform.dom.DOMResult */ public XMLDOMWriterImpl(DOMResult result) { node = result.getNode(); if( node.getNodeType() == Node.DOCUMENT_NODE){ ownerDoc = (Document)node; currentNode = ownerDoc; }else{ ownerDoc = node.getOwnerDocument(); currentNode = node; } getDLThreeMethods(); stringBuffer = new StringBuffer(); needContextPop = new boolean[resizeValue]; namespaceContext = new NamespaceSupport(); }
Example #11
Source File: W3CDomHandler.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public Element getElement(DOMResult r) { // JAXP spec is ambiguous about what really happens in this case, // so work defensively Node n = r.getNode(); if( n instanceof Document ) { return ((Document)n).getDocumentElement(); } if( n instanceof Element ) return (Element)n; if( n instanceof DocumentFragment ) return (Element)n.getChildNodes().item(0); // if the result object contains something strange, // it is not a user problem, but it is a JAXB provider's problem. // That's why we throw a runtime exception. throw new IllegalStateException(n.toString()); }
Example #12
Source File: XmlUtil.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Transform one document into another * * @param document source Document * @param stylesheet XSLT Document * * @return transformed Document */ public static Document transformDocument( Document document, Document stylesheet) { if(log.isDebugEnabled()) { log.debug( "Document transformDocument(Document " + document + ", Document " + stylesheet + ")"); } Document transformedDoc = createDocument(); DOMSource docSource = new DOMSource(document); DOMResult docResult = new DOMResult(transformedDoc); Transformer transformer = createTransformer(stylesheet); transform(transformer, docSource, docResult); // log.debug("INPUT DOCUMENT: \n" + (document)); // log.debug("TRANSFORM DOCUMENT: \n" + getDOMString(stylesheet)); // log.debug("OUTPUT DOCUMENT: \n" + getDOMString(transformedDoc)); return transformedDoc; }
Example #13
Source File: XMLStreamWriterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * @bug 8139584 * Verifies that the resulting XML contains the standalone setting. */ @Test public void testCreateStartDocument_DOMWriter() throws ParserConfigurationException, XMLStreamException { XMLOutputFactory xof = XMLOutputFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.newDocument(); XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc)); XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true); eventWriter.add(event); eventWriter.flush(); Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15"); Assert.assertEquals(doc.getXmlVersion(), "1.0"); Assert.assertTrue(doc.getXmlStandalone()); }
Example #14
Source File: XStreamMarshallerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void marshalDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); Document document = builder.newDocument(); DOMResult domResult = new DOMResult(document); marshaller.marshal(flight, domResult); Document expected = builder.newDocument(); Element flightElement = expected.createElement("flight"); expected.appendChild(flightElement); Element numberElement = expected.createElement("flightNumber"); flightElement.appendChild(numberElement); Text text = expected.createTextNode("42"); numberElement.appendChild(text); assertThat("Marshaller writes invalid DOMResult", document, isSimilarTo(expected)); }
Example #15
Source File: AbstractMarshallerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void marshalEmptyDOMResult() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); DOMResult domResult = new DOMResult(); marshaller.marshal(flights, domResult); assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document); Document result = (Document) domResult.getNode(); Document expected = builder.newDocument(); Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights"); Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns"); namespace.setNodeValue("http://samples.springframework.org/flight"); flightsElement.setAttributeNode(namespace); expected.appendChild(flightsElement); Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight"); flightsElement.appendChild(flightElement); Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number"); flightElement.appendChild(numberElement); Text text = expected.createTextNode("42"); numberElement.appendChild(text); assertThat("Marshaller writes invalid DOMResult", result, isSimilarTo(expected)); }
Example #16
Source File: DomXmlDataFormatMapper.java From camunda-spin with Apache License 2.0 | 6 votes |
@Override public Object mapJavaToInternal(Object parameter) { ensureNotNull("Parameter", parameter); final Class<?> parameterClass = parameter.getClass(); final DOMResult domResult = new DOMResult(); try { Marshaller marshaller = getMarshaller(parameterClass); boolean isRootElement = parameterClass.getAnnotation(XmlRootElement.class) != null; if(isRootElement) { marshalRootElement(parameter, marshaller, domResult); } else { marshalNonRootElement(parameter, marshaller, domResult); } Node node = domResult.getNode(); return ((Document)node).getDocumentElement(); } catch (JAXBException e) { throw LOG.unableToMapInput(parameter, e); } }
Example #17
Source File: W3CDomHandler.java From JDKSourceCode1.8 with MIT License | 6 votes |
public Element getElement(DOMResult r) { // JAXP spec is ambiguous about what really happens in this case, // so work defensively Node n = r.getNode(); if( n instanceof Document ) { return ((Document)n).getDocumentElement(); } if( n instanceof Element ) return (Element)n; if( n instanceof DocumentFragment ) return (Element)n.getChildNodes().item(0); // if the result object contains something strange, // it is not a user problem, but it is a JAXB provider's problem. // That's why we throw a runtime exception. throw new IllegalStateException(n.toString()); }
Example #18
Source File: DOMResultBuilder.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void setDOMResult(DOMResult result) { fCurrentNode = null; fFragmentRoot = null; fIgnoreChars = false; fTargetChildren.clear(); if (result != null) { fTarget = result.getNode(); fNextSibling = result.getNextSibling(); fDocument = (fTarget.getNodeType() == Node.DOCUMENT_NODE) ? (Document) fTarget : fTarget.getOwnerDocument(); fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null; fStorePSVI = (fDocument instanceof PSVIDocumentImpl); return; } fTarget = null; fNextSibling = null; fDocument = null; fDocumentImpl = null; fStorePSVI = false; }
Example #19
Source File: AbstractStaxHandlerTestCase.java From spring-analysis-note with MIT License | 6 votes |
@Test public void noNamespacePrefixesDom() throws Exception { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document expected = documentBuilder.parse(new InputSource(new StringReader(SIMPLE_XML))); Document result = documentBuilder.newDocument(); AbstractStaxHandler handler = createStaxHandler(new DOMResult(result)); xmlReader.setContentHandler(handler); xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler); xmlReader.setFeature("http://xml.org/sax/features/namespaces", true); xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false); xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML))); assertThat(result, isSimilarTo(expected).withNodeFilter(nodeFilter)); }
Example #20
Source File: TransformerHandlerImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Implements org.xml.sax.ContentHandler.endDocument() * Receive notification of the end of a document. */ @Override public void endDocument() throws SAXException { // Signal to the DOMBuilder that the document is complete _handler.endDocument(); if (!_isIdentity) { // Run the transformation now if we have a reference to a Result object if (_result != null) { try { _transformer.setDOM(_dom); _transformer.transform(null, _result); } catch (TransformerException e) { throw new SAXException(e); } } // Signal that the internal DOM is built (see 'setResult()'). _done = true; // Set this DOM as the transformer's DOM _transformer.setDOM(_dom); } if (_isIdentity && _result instanceof DOMResult) { ((DOMResult)_result).setNode(_transformer.getTransletOutputHandlerFactory().getNode()); } }
Example #21
Source File: SmartTransformerFactoryImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * javax.xml.transform.sax.TransformerFactory implementation. * Look up the value of a feature (to see if it is supported). * This method must be updated as the various methods and features of this * class are implemented. * * @param name The feature name * @return 'true' if feature is supported, 'false' if not */ public boolean getFeature(String name) { // All supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, SAXSource.FEATURE, SAXResult.FEATURE, StreamSource.FEATURE, StreamResult.FEATURE }; // feature name cannot be null if (name == null) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); } // Inefficient, but it really does not matter in a function like this for (int i = 0; i < features.length; i++) { if (name.equals(features[i])) return true; } // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { return featureSecureProcessing; } // unknown feature return false; }
Example #22
Source File: XSLTUtils.java From cxf with Apache License 2.0 | 5 votes |
public static Document transform(Templates xsltTemplate, Document in) { try { DOMSource beforeSource = new DOMSource(in); Document out = DOMUtils.createDocument(); Transformer trans = xsltTemplate.newTransformer(); trans.transform(beforeSource, new DOMResult(out)); return out; } catch (TransformerException e) { throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage()); } }
Example #23
Source File: LogicalMessageImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public Source getPayload() { assert (!(payloadSrc instanceof DOMSource)); try { Transformer transformer = XmlUtil.newTransformer(); DOMResult domResult = new DOMResult(); transformer.transform(payloadSrc, domResult); DOMSource dom = new DOMSource(domResult.getNode()); lm = new DOMLogicalMessageImpl((DOMSource) dom); payloadSrc = null; return dom; } catch (TransformerException te) { throw new WebServiceException(te); } }
Example #24
Source File: SmartTransformerFactoryImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * javax.xml.transform.sax.TransformerFactory implementation. * Look up the value of a feature (to see if it is supported). * This method must be updated as the various methods and features of this * class are implemented. * * @param name The feature name * @return 'true' if feature is supported, 'false' if not */ public boolean getFeature(String name) { // All supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, SAXSource.FEATURE, SAXResult.FEATURE, StreamSource.FEATURE, StreamResult.FEATURE }; // feature name cannot be null if (name == null) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); } // Inefficient, but it really does not matter in a function like this for (int i = 0; i < features.length; i++) { if (name.equals(features[i])) return true; } // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { return featureSecureProcessing; } // unknown feature return false; }
Example #25
Source File: SmartTransformerFactoryImpl.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * javax.xml.transform.sax.TransformerFactory implementation. * Look up the value of a feature (to see if it is supported). * This method must be updated as the various methods and features of this * class are implemented. * * @param name The feature name * @return 'true' if feature is supported, 'false' if not */ public boolean getFeature(String name) { // All supported features should be listed here String[] features = { DOMSource.FEATURE, DOMResult.FEATURE, SAXSource.FEATURE, SAXResult.FEATURE, StreamSource.FEATURE, StreamResult.FEATURE }; // feature name cannot be null if (name == null) { ErrorMsg err = new ErrorMsg(ErrorMsg.JAXP_GET_FEATURE_NULL_NAME); throw new NullPointerException(err.toString()); } // Inefficient, but it really does not matter in a function like this for (int i = 0; i < features.length; i++) { if (name.equals(features[i])) return true; } // secure processing? if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { return featureSecureProcessing; } // unknown feature return false; }
Example #26
Source File: Jdbc4SqlXmlHandler.java From effectivejava with Apache License 2.0 | 5 votes |
@Override public SqlXmlValue newSqlXmlValue(final Document document) { return new AbstractJdbc4SqlXmlValue() { @Override protected void provideXml(SQLXML xmlObject) throws SQLException, IOException { xmlObject.setResult(DOMResult.class).setNode(document); } }; }
Example #27
Source File: TransformerHandlerImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Implements org.xml.sax.ContentHandler.endDocument() * Receive notification of the end of a document. */ @Override public void endDocument() throws SAXException { // Signal to the DOMBuilder that the document is complete _handler.endDocument(); if (!_isIdentity) { // Run the transformation now if we have a reference to a Result object if (_result != null) { try { _transformer.setDOM(_dom); _transformer.transform(null, _result); } catch (TransformerException e) { throw new SAXException(e); } } // Signal that the internal DOM is built (see 'setResult()'). _done = true; // Set this DOM as the transformer's DOM _transformer.setDOM(_dom); } if (_isIdentity && _result instanceof DOMResult) { ((DOMResult)_result).setNode(_transformer.getTransletOutputHandlerFactory().getNode()); } }
Example #28
Source File: StaxSourceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void streamReaderSourceToDOMResult() throws Exception { XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(XML)); StaxSource source = new StaxSource(streamReader); assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader()); assertNull("EventReader returned", source.getXMLEventReader()); Document expected = documentBuilder.parse(new InputSource(new StringReader(XML))); Document result = documentBuilder.newDocument(); transformer.transform(source, new DOMResult(result)); assertThat("Invalid result", result, isSimilarTo(expected)); }
Example #29
Source File: ParseDOM.java From jlibs with Apache License 2.0 | 5 votes |
@Override protected void addHandlers(AsyncXMLReader xmlReader) throws Exception{ TransformerHandler handler = TransformerUtil.newTransformerHandler(null, false, -1, null); SAXUtil.setHandler(xmlReader, handler); DOMResult result = createDOMResult(); handler.setResult(result); handler.getTransformer().setParameter(DOMResult.class.getName(), result); }
Example #30
Source File: StaxSourceTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void eventReaderSourceToDOMResult() throws Exception { XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML)); StaxSource source = new StaxSource(eventReader); assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader()); assertNull("StreamReader returned", source.getXMLStreamReader()); Document expected = documentBuilder.parse(new InputSource(new StringReader(XML))); Document result = documentBuilder.newDocument(); transformer.transform(source, new DOMResult(result)); assertThat("Invalid result", result, isSimilarTo(expected)); }