Java 8 XMLStreamWriter - 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 XMLStreamWriter class.

This code example shows how to use the following methods:getPrefix, writeCharacters, writeEndElement, writeNamespace, writeStartElement
    public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
        Class<?> jtype = part.getTypeClass();
        QName stype = part.getTypeQName();
        if (JibxSimpleTypes.isSimpleType(jtype)) {
            try { 
                String pfx = output.getPrefix(part.getConcreteName().getNamespaceURI());
                if (StringUtils.isEmpty(pfx)) {
                    output.writeStartElement("tns", part.getConcreteName().getLocalPart(), part
                        .getConcreteName().getNamespaceURI()); 
                    output.writeNamespace("tns", part.getConcreteName().getNamespaceURI());
                } else { 
                    output.writeStartElement(pfx, part.getConcreteName().getLocalPart(), part
                        .getConcreteName().getNamespaceURI()); 
                } 
                output.writeCharacters(JibxSimpleTypes.toText(stype, obj));
                output.writeEndElement();
            } catch (XMLStreamException e) {
                throw new RuntimeException(e);
            } 
        } else { 
            try { 
7
CodeRank
This code example shows how to use the following methods:writeCharacters
		this.streamWriter.writeEndElement();
	} 
 
	@Override 
	protected void charactersInternal(String data) throws XMLStreamException {
		this.streamWriter.writeCharacters(data);
	} 
 
	@Override 
	protected void cDataInternal(String data) throws XMLStreamException {
		this.streamWriter.writeCData(data);
	} 
 
	@Override 
	protected void ignorableWhitespaceInternal(String data) throws XMLStreamException {
		this.streamWriter.writeCharacters(data);
	} 
 
	@Override 
	protected void processingInstructionInternal(String target, String data) throws XMLStreamException {
7
CodeRank
This code example shows how to use the following methods:close, flush
    } 
 
    public void stopWrite () 
           throws IOException, XMLStreamExceptionxmlWriter.flush();
        xmlWriter.close();
        outputStream.close();	
    } 
     
    // Cooperate with an instance of org.apache.axis2.databinding.ADBBean to provide serialization output of XML 
    // An org.apache.axis2.databinding.ADBBean implements a serialize method which takes a QName and a XMLStreamWriter 
    public void writeout 
        (ADBBean dataBindingBean) throws ADBException, XMLStreamException
    { 
    	 
    	dataBindingBean.serialize(qualifiedName, omfactory, mtomWriter);
    } 
 
  } 
7
CodeRank
This code example shows how to use the following methods:close, flush, writeEndDocument
 
    @Override 
    protected void onSerializationEnd( Object object, XMLStreamWriter output )
        throws Exceptionoutput.writeEndDocument();
        output.flush();
        output.close();
    } 
 
    @Override 
    protected void onArrayStart( XMLStreamWriter output )
        throws Exceptionoutput.writeStartElement( "array" );
    } 
 
    @Override 
    protected void onArrayEnd( XMLStreamWriter output )
        throws Exception
7
CodeRank
This code example shows how to use the following methods:getNamespaceContext, setPrefix, writeNamespace
                if (!StringUtils.isEmpty(namespace)) {
                    declare = true;
                    prefix = StaxUtils.getUniquePrefix(writer);
                } else { 
                    prefix = "";
                    if (!StringUtils.isEmpty(writer.getNamespaceContext().getNamespaceURI(""))) {
                        declare = true;
                    } 
                } 
            } else if (StringUtils.isEmpty(prefix)) {
                prefix = decPrefix;
            } else if (!prefix.equals(decPrefix)) {
                declare = true;
            } 
 
            writer.writeStartElement(prefix, name, namespace);
 
            if (declare) {
                writer.setPrefix(prefix, namespace);
                writer.writeNamespace(prefix, namespace);

7
CodeRank
This code example shows how to use the following methods:getNamespaceContext, setPrefix, writeNamespace
 
    public void close() { 
    } 
} 

7
CodeRank
This code example shows how to use the following methods:close, flush
    @Override 
    public byte[] serialize(MediaContent content) throws ExceptionByteArrayOutputStream baos = outputStream(content);
        XMLStreamWriter writer = createWriter(baos);
        _serializer.writeDocument(writer, content);
        writer.flush();
        writer.close();
        return baos.toByteArray();
    } 
 
    @Override 
    public final void serializeItems(MediaContent[] items, OutputStream out) throws XMLStreamException
    { 
        // XML requires single root, so add bogus "stream" 
        XMLStreamWriter writer = createWriter(out);
        _serializer.writeDocument(writer, items);
        writer.flush();
        writer.close();
    } 
7
CodeRank
This code example shows how to use the following methods:getNamespaceContext, setPrefix, writeNamespace
                                         String preferred,
                                         boolean declare)
        throws XMLStreamException {
         
        if (preferred != null) {
            String existing = writer.getNamespaceContext().getNamespaceURI(preferred);
            if (namespaceURI.equals(existing)) {
                return preferred;
            } 
        } 
        String prefix = preferred; 
        if (prefix == null) {
            prefix = writer.getNamespaceContext().getPrefix(namespaceURI);
            if (prefix != null) {
                declare = false;
            } 
        } 
         
        if (prefix == null) {
            prefix = StaxUtils.getUniquePrefix(writer);

7
CodeRank
This code example shows how to use the following methods:setPrefix, writeDefaultNamespace, writeNamespace, writeStartElement
                Service service = message.getExchange().get(Service.class);
                if (service.getDataBinding().getDeclaredNamespaceMappings() != null) { 
                    pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
                } 
                if (pfx == null) {
                    pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
                } 
                xmlWriter.setPrefix(pfx, name.getNamespaceURI());
                xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
                if (StringUtils.isEmpty(pfx)) {
                    xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
                } else { 
                    xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
                } 
            } catch (XMLStreamException e) {
                throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
            } 
 
            // Add a final interceptor to write end element 
            message.getInterceptorChain().add(ending);
6
CodeRank
This code example shows how to use the following methods:close, writeCharacters, writeEndDocument, writeEndElement, writeStartDocument
	 */ 
	@Test
	public void testString() throws Exception {
		StringWriter result = new StringWriter();
		XMLStreamWriter writer = createXmlStreamWriter(result);
		writer.writeStartDocument();
		writer.writeStartElement("alice");
		writer.writeCharacters("bob");
		writer.writeEndElement();
		writer.writeEndDocument();
		writer.close();
		Assert.assertEquals("{\"alice\":\"bob\"}", result.toString());
	} 
 
	/** 
	 * <code>&lt;alice edgar=\"999\" &gt;&lt;bob&gt;123&lt;/bob&gt;&lt;bob&gt;123.4&lt;/bob&gt;&lt;/alice&gt;</code> 
	 */ 
	@Test
	public void testNumber() throws Exception {
		StringWriter result = new StringWriter();
6
CodeRank
See Code Examples for Java 8 XMLStreamWriter Methods: