Preserve comments when using JibxMarshaller

Prior to this commit, JibxMarshaller used a SAX ContentHandler to
marshal to StAX XMLEventWriters, which inadvertently resulted in the
deletion of XML comments.

After this commit, JibxMarshaller adapts the XMLEventWriter into an
XMLStreamWriter and comments are preserved.

Issue: SPR-9768
This commit is contained in:
Arjen Poutsma
2012-09-14 09:48:25 +02:00
committed by Chris Beams
parent 17c6515c0a
commit f191a55b8f
4 changed files with 18 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -309,6 +309,15 @@ public abstract class StaxUtils {
return new XMLEventStreamReader(eventReader);
}
/**
* Return a {@link XMLStreamWriter} that writes to a {@link XMLEventWriter}.
* @return a stream writer that writes to an event writer
* @since 3.2
*/
public static XMLStreamWriter createEventStreamWriter(XMLEventWriter eventWriter) {
return new XMLEventStreamWriter(eventWriter, XMLEventFactory.newFactory());
}
/**
* Return a {@link XMLStreamWriter} that writes to a {@link XMLEventWriter}.
* @return a stream writer that writes to an event writer

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -193,7 +193,7 @@ class XMLEventStreamWriter implements XMLStreamWriter {
private void writeStartElement(StartElement startElement) throws XMLStreamException {
eventWriter.add(startElement);
endElements.add(eventFactory.createEndElement(startElement.getName(), null));
endElements.add(eventFactory.createEndElement(startElement.getName(), startElement.getNamespaces()));
}
private void writeNamespace(Namespace namespace) throws XMLStreamException {