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

This code example shows how to use the following methods:add, close, flush, setDefaultNamespace
        catch (XMLStreamException e) {
            throw new RuntimeException("Failed to create XMLEventWriter", e);
        } 
         
        try { 
            xmlEventWriter.setDefaultNamespace("http://www.w3.org/1999/xhtml");
            xmlEventWriter.add(reader);
            xmlEventWriter.flush();
            xmlEventWriter.close();
        } 
        catch (XMLStreamException e) {
            throw new RuntimeException("Failed to write events to Writer", e);
        } 
         
        return writer.toString();
    } 
     
    protected XMLEventReader getXmlEventReader(String file) throws SAXException, IOException, ParserConfigurationException {
        final InputStream xmlStream = this.getClass().getResourceAsStream(file);
         
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add, close
	@Override 
	public void writeEndElement() throws XMLStreamException {
		closeEmptyElementIfNecessary(); 
		int last = this.endElements.size() - 1;
		EndElement lastEndElement = this.endElements.get(last);
		this.eventWriter.add(lastEndElement);
		this.endElements.remove(last);
	} 
 
	@Override 
	public void writeAttribute(String localName, String value) throws XMLStreamException {
		this.eventWriter.add(this.eventFactory.createAttribute(localName, value));
	} 
 
	@Override 
	public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
		this.eventWriter.add(this.eventFactory.createAttribute(new QName(namespaceURI, localName), value));
	} 
 
	@Override 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add
		} 
	} 
 
	@Override 
	protected void startDocumentInternal() throws XMLStreamException {
		this.eventWriter.add(this.eventFactory.createStartDocument());
	} 
 
	@Override 
	protected void endDocumentInternal() throws XMLStreamException {
		this.eventWriter.add(this.eventFactory.createEndDocument());
	} 
 
	@Override 
	protected void startElementInternal(QName name, Attributes atts,
			Map<String, String> namespaceMapping) throws XMLStreamException {
 
		List<Attribute> attributes = getAttributes(atts);
		List<Namespace> namespaces = getNamespaces(namespaceMapping);
		this.eventWriter.add(
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add, close, flush
This code example shows how to use the following methods:close, flush
         
        StringWriter stringWriter = new StringWriter();
        XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
        opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
        XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
        JAXBEncoderDecoder.marshall(context.createMarshaller(), testObject, part, writer);
        writer.flush();
        writer.close();
        String xmlResult = stringWriter.toString();
        // the following is a bit of a crock, but, to tell the truth, this test case most exists 
        // so that it could be examined inside the debugger to see how JAXB works. 
        assertTrue(xmlResult.contains(":string2>cord</ns"));
    } 
     
    @Test
    public void testCustomNamespaces() throws Exception {
        Map<String, String> mapper = new HashMap<String, String>();
        mapper.put("http://apache.org/hello_world_soap_http/types", "Omnia");
        mapper.put("http://cxf.apache.org/jaxb_form", "Gallia");
        ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add, close, flush
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add
		wrappedEventWriter.add(event);
	} 
 
    @Override 
	public void add(XMLEventReader reader) throws XMLStreamException {
		wrappedEventWriter.add(reader);
	} 
 
    @Override 
	public void close() throws XMLStreamException {
		wrappedEventWriter.close();
	} 
 
    @Override 
	public void flush() throws XMLStreamException {
		wrappedEventWriter.flush();
	} 
 
    @Override 
	public NamespaceContext getNamespaceContext() {
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add
	 */ 
	public void testNoStartEnd() throws Exception {
		XMLEvent event = eventFactory.createComment("testEvent");
 
		// mock expects only a single event 
		wrappedWriter.add(event);
 
		writer.add(eventFactory.createStartDocument());
		writer.add(event);
		writer.add(eventFactory.createEndDocument());
 
	} 
	 
	/** 
	 * Close is not delegated to the wrapped writer. Instead, the wrapped writer is flushed. 
	 */ 
	public void testClose() throws Exception {
		writer.close();
		 
		verify(wrappedWriter, times(1)).flush();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:add, flush
 
	@Override 
	public synchronized void close(final TaskAttemptContext paramContext)
			throws IOException, InterruptedException {
		try { 
			mWriter.add(mEventFactory.createEndElement(mRootElem.getName(), null));
			mWriter.flush();
		} catch (final XMLStreamException e) {
			LOGWRAPPER.error(e.getMessage(), e);
		} 
	} 
 
	@Override 
	public synchronized void write(final K paramKey, final V paramValue)
			throws IOException, InterruptedException {
		if (paramValue instanceof XMLEvent) {
			final XMLEvent[] events = (XMLEvent[]) paramValue;
			for (final XMLEvent event : events) {
				try { 
					mWriter.add(event);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty
 
   @Test
   public void marshallAppCategories() throws Exception {
       JAXBContext jaxbContext=JAXBContext.newInstance("org.jboss.resteasy.test.providers.atom.app");
       Marshaller marshaller = jaxbContext.createMarshaller();
       marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
       marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
       marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
       
       AppCategories appCategories = new AppCategories();
       appCategories.setFixed(true);
       appCategories.setScheme("http://example.com/cats/big3");
       Category category1 = new Category();
       category1.setTerm("animal");
       appCategories.getCategory().add(category1);
       Category category2 = new Category();
       category2.setTerm("vegetable");
       appCategories.getCategory().add(category2);
       Category category3 = new Category();
       category3.setTerm("mineral");

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 XMLEventWriter Methods: