Java 8 StAXResult - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 StAXResult class.

This code example shows how to use the following methods:
 
	@Test
	public void isStaxResultJaxp14() throws Exception {
		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
		XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
		StAXResult result = new StAXResult(streamWriter);
 
		assertTrue("Not a StAX Result", StaxUtils.isStaxResult(result));
	} 
 
} 
7
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
	 * Create a JAXP 1.4 {@link StAXResult} for the given {@link XMLStreamWriter}. 
	 * @param streamWriter the StAX stream writer 
	 * @return a result wrapping the {@code streamWriter} 
	 */ 
	public static Result createStaxResult(XMLStreamWriter streamWriter) {
		return new StAXResult(streamWriter);
	} 
 
	/** 
	 * Create a JAXP 1.4 {@link StAXResult} for the given {@link XMLEventWriter}. 
	 * @param eventWriter the StAX event writer 
	 * @return a result wrapping {@code streamReader} 
	 */ 
	public static Result createStaxResult(XMLEventWriter eventWriter) {
		return new StAXResult(eventWriter);
	} 
 
	/** 
	 * Create a custom, non-JAXP 1.4 StAX {@link Result} for the given {@link XMLStreamWriter}. 
	 * @param streamWriter the StAX stream writer 
6
CodeRank
This code example shows how to use the following methods:
			final TransformerFactory tf = TransformerFactory.newInstance(
					"com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", 
					this.getClass().getClassLoader());
			final Transformer t = tf.newTransformer();
			StAXSource source = new StAXSource(sr.output(doc));
			StAXResult result = new StAXResult(sw);
			t.transform(source, result);
			return sw.getDocument();
		} catch (Exception e) {
			throw new IllegalStateException("Failed to identity-trasform...", e);
		} 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
 
    @Override 
    public void marshal(Object jaxbElement, 
            javax.xml.stream.XMLStreamWriter writer)
            throws IOException {
        this.marshaller.marshal(jaxbElement, new StAXResult(writer));
    } 
 
    @Override 
    public void marshal(Object jaxbElement, 
            javax.xml.stream.XMLEventWriter writer)
            throws IOException {
        this.marshaller.marshal(jaxbElement, new StAXResult(writer));
    } 
 
    @Override 
    public Object unmarshal(java.io.File f) throws IOException {
        return this.marshaller.unmarshal(
                new StreamSource(new FileInputStream(f)));
    } 
5
CodeRank
This code example shows how to use the following methods:
 
    @Override 
    public void marshal(Object jaxbElement, 
            javax.xml.stream.XMLStreamWriter writer)
            throws IOException {
        this.marshaller.marshal(jaxbElement, new StAXResult(writer));
    } 
 
    @Override 
    public void marshal(Object jaxbElement, 
            javax.xml.stream.XMLEventWriter writer)
            throws IOException {
        this.marshaller.marshal(jaxbElement, new StAXResult(writer));
    } 
 
    @Override 
    public Object unmarshal(java.io.File f) throws IOException {
        return this.marshaller.unmarshal(
                new StreamSource(new FileInputStream(f)));
    } 
5
CodeRank
This code example shows how to use the following methods:
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
        Writer writer = new OutputStreamWriter(new FileOutputStream(output));
 
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer);
 
        this.marshaller.marshal(jaxbElement, new StAXResult(xmlStreamWriter));
    } 
 
    @Override 
    public void marshal(Object jaxbElement, Writer writer) throws IOException {
        Configuration config = new Configuration(); 
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
 
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer);
 
        this.marshaller.marshal(jaxbElement, new StAXResult(xmlStreamWriter));
    } 
 
    @Override 
    public Object unmarshal(File f) throws Exception {
5
CodeRank
This code example shows how to use the following methods:getXMLEventWriter, getXMLStreamWriter
            // SAXResult is not supported by the standard XMLOutputFactory 
            xmlStreamWriter = new XMLEventStreamWriter(new SAXEventWriter(((SAXResult) result).getHandler()));
        } else if (result instanceof StAXResult) {
            // XMLEventWriter is not supported as result of XMLOutputFactory#createXMLStreamWriter 
            StAXResult staxResult = (StAXResult) result;
            if (staxResult.getXMLStreamWriter() != null) {
                xmlStreamWriter = staxResult.getXMLStreamWriter();
            } else { 
                xmlStreamWriter = new XMLEventStreamWriter(staxResult.getXMLEventWriter());
            } 
        } else { 
            xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(result);
        } 
 
        return xmlStreamWriter;
    } 
 
    /** 
     * Go to the end of the current element. This include skipping any children element. 
     * 
5
CodeRank
This code example shows how to use the following methods:
 
            if (properties.isFormat()) {
                xmlStreamWriter = new IndentingXMLStreamWriter(xmlStreamWriter);
            } 
 
            result = new StAXResult(xmlStreamWriter);
        } 
 
        return result;
    } 
 
    @Override 
    public Object getFilter() throws FilterException 
    { 
        if (this.filter == null) {
            try { 
                this.filter = createFilter(this.properties);
            } catch (Exception e) {
                throw new FilterException("Failed to create filter", e);
            } 
4
CodeRank
See Code Examples for Java 8 StAXResult Methods: