Merge pull request #147 from poutsma/SPR-9768
# By Arjen Poutsma * SPR-9768: Preserve comments when using JibxMarshaller
This commit is contained in:
commit
ccd7b10237
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 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.
|
||||
|
@ -29,8 +29,7 @@ import static org.custommonkey.xmlunit.XMLAssert.*;
|
|||
public class XMLEventStreamWriterTests {
|
||||
|
||||
private static final String XML =
|
||||
"<?pi content?><root xmlns='namespace'><prefix:child xmlns:prefix='namespace2'>content</prefix:child></root>"
|
||||
;
|
||||
"<?pi content?><root xmlns='namespace'><prefix:child xmlns:prefix='namespace2'><!--comment-->content</prefix:child></root>";
|
||||
|
||||
private XMLEventStreamWriter streamWriter;
|
||||
|
||||
|
@ -52,6 +51,7 @@ public class XMLEventStreamWriterTests {
|
|||
streamWriter.writeDefaultNamespace("namespace");
|
||||
streamWriter.writeStartElement("prefix", "child", "namespace2");
|
||||
streamWriter.writeNamespace("prefix", "namespace2");
|
||||
streamWriter.writeComment("comment");
|
||||
streamWriter.writeCharacters("content");
|
||||
streamWriter.writeEndElement();
|
||||
streamWriter.writeEndElement();
|
||||
|
|
|
@ -338,8 +338,8 @@ public class JibxMarshaller extends AbstractMarshaller implements InitializingBe
|
|||
|
||||
@Override
|
||||
protected void marshalXmlEventWriter(Object graph, XMLEventWriter eventWriter) {
|
||||
ContentHandler contentHandler = StaxUtils.createContentHandler(eventWriter);
|
||||
marshalSaxHandlers(graph, contentHandler, null);
|
||||
XMLStreamWriter streamWriter = StaxUtils.createEventStreamWriter(eventWriter);
|
||||
marshalXmlStreamWriter(graph, streamWriter);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue