Hi,
The getOutputStream() method only worked for writer's based on
StreamWriterBase -- this did not account for the GenericXMLWriter which,
heh, uses a Writer and thus does not output to a _stream_. So, here's a
revised take on the idea being able to output XML content directly to a
writer.
* Created IRawXMLWriter interface to expose direct write methods;
added it to XMLWriterNamespaceBase which also implements IXMLWriter.
* added implementations to GenericXMLWriter and StreamWriterBase.
It works for my limited use case - my custom marshaller is able to emit
pre-serialized XML content directly into another documents stream. It
also shields existing users of the IXMLWriter interface from anything to
do with this change.
Here's a simple example of what it would look like (assume 'xml' has
been previously populated):
IXMLWriter writer = ctx.getXmlWriter();
IRawXMLWriter rawWriter = (IRawXMLWriter)writer;
rawWriter.writeRawMarkup(xml);
Other code snippets below. It ain't pretty, but it can be very useful.
Any questions, queries, or comments? Is this worthy of inclusion into
JiBX?
...Leif
---------[ IRawXMLWriter ]----------
public interface IRawXMLWriter
{
/**
* Write previously serialized XML content directly to output
* without any escaping. It is assumed that the character XML
* content has already been escaped.
*
* Output encoding may still occur, depending on the underlying
* implementation (i.e. only if output is stream based).
*
* @param xml XML content in java.lang.String form.
* @throws IOException on error writing to document
*/
public void writeRawMarkup(String xml) throws IOException;
/**
* Write a single character to the output. Since no escaping
* will be performed, this method should be used with extreme
* care.
*
* @param ch A single character to write to the XML document.
* @throws IOException on error writing to document
*/
public void writeRawMarkup(char ch) throws IOException;
}
---------[ StreamWriterBase methods from IRawXMLWriter ]----------
public void writeRawMarkup(String xml) throws IOException {
// we flush first to be sure no writes are pending from
// this classes internal buffer...
flush();
m_stream.write(xml.getBytes());
}
public void writeRawMarkup(char ch) throws IOException {
// we flush first to be sure no writes are pending from
// this classes internal buffer...
flush();
m_stream.write(ch);
}
---------[ GenericXMLWriter methods from IRawXMLWriter ]----------
public void writeRawMarkup(String xml) throws IOException {
writeMarkup(xml);
}
public void writeRawMarkup(char ch) throws IOException {
writeMarkup(ch);
}
---------[ end ]----------
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users