Search in sources :

Example 11 with Result

use of javax.xml.transform.Result in project spring-framework by spring-projects.

the class Jaxb2MarshallerTests method marshalAWrappedObjectHoldingAnXmlElementDeclElement.

@Test
public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Exception {
    // SPR-10714
    marshaller = new Jaxb2Marshaller();
    marshaller.setPackagesToScan(new String[] { "org.springframework.oxm.jaxb" });
    marshaller.afterPropertiesSet();
    Airplane airplane = new Airplane();
    airplane.setName("test");
    StringWriter writer = new StringWriter();
    Result result = new StreamResult(writer);
    marshaller.marshal(airplane, result);
    DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE));
    assertThat("Marshalling should use root Element", writer.toString(), isSimilarTo("<airplane><name>test</name></airplane>").withDifferenceEvaluator(ev));
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) SAXResult(javax.xml.transform.sax.SAXResult) DifferenceEvaluator(org.xmlunit.diff.DifferenceEvaluator) Test(org.junit.Test)

Example 12 with Result

use of javax.xml.transform.Result in project spring-framework by spring-projects.

the class XStreamMarshallerTests method marshalStaxResultXMLEventWriter.

@Test
public void marshalStaxResultXMLEventWriter() throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    StringWriter writer = new StringWriter();
    XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer);
    Result result = StaxUtils.createStaxResult(eventWriter);
    marshaller.marshal(flight, result);
    assertThat("Marshaller writes invalid StreamResult", writer.toString(), isSimilarTo(EXPECTED_STRING));
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) SAXResult(javax.xml.transform.sax.SAXResult) DOMResult(javax.xml.transform.dom.DOMResult) Test(org.junit.Test)

Example 13 with Result

use of javax.xml.transform.Result in project dbeaver by serge-rider.

the class DBDDocumentXML method serializeDocument.

@Override
public void serializeDocument(@NotNull DBRProgressMonitor monitor, @NotNull OutputStream stream, String encoding) throws DBException {
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        Result output = new StreamResult(new OutputStreamWriter(stream, encoding));
        transformer.transform(new DOMSource(document), output);
    } catch (Exception e) {
        throw new DBException("Error serializing XML document", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) DBException(org.jkiss.dbeaver.DBException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) DOMResult(javax.xml.transform.dom.DOMResult)

Example 14 with Result

use of javax.xml.transform.Result in project camel by apache.

the class XQueryBuilder method evaluateAsBytes.

public byte[] evaluateAsBytes(Exchange exchange) throws Exception {
    LOG.debug("evaluateAsBytes: {} for exchange: {}", expression, exchange);
    initialize(exchange);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    Result result = new StreamResult(buffer);
    getExpression().pull(createDynamicContext(exchange), result, properties);
    byte[] answer = buffer.toByteArray();
    buffer.close();
    return answer;
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) DOMResult(javax.xml.transform.dom.DOMResult)

Example 15 with Result

use of javax.xml.transform.Result in project asciidoctor-fopub by asciidoctor.

the class InputHandler method transformTo.

/**
     * In contrast to render(Fop) this method only performs the XSLT stage and saves the
     * intermediate XSL-FO file to the output file.
     * @param out OutputStream to write the transformation result to.
     * @throws FOPException in case of an error during processing
     */
public void transformTo(OutputStream out) throws FOPException {
    Result res = new StreamResult(out);
    transformTo(res);
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) SAXResult(javax.xml.transform.sax.SAXResult)

Aggregations

Result (javax.xml.transform.Result)68 StreamResult (javax.xml.transform.stream.StreamResult)60 Source (javax.xml.transform.Source)42 Transformer (javax.xml.transform.Transformer)42 DOMSource (javax.xml.transform.dom.DOMSource)33 TransformerFactory (javax.xml.transform.TransformerFactory)25 StringWriter (java.io.StringWriter)21 StreamSource (javax.xml.transform.stream.StreamSource)19 IOException (java.io.IOException)18 TransformerException (javax.xml.transform.TransformerException)17 SAXResult (javax.xml.transform.sax.SAXResult)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 File (java.io.File)11 Document (org.w3c.dom.Document)11 InputSource (org.xml.sax.InputSource)10 DocumentBuilder (javax.xml.parsers.DocumentBuilder)9 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)9 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)9 DOMResult (javax.xml.transform.dom.DOMResult)9 SAXException (org.xml.sax.SAXException)9