The concept is not very much different. your XMLOutputter writes the xml data to target Writer or OutputStream. In your code, it is being written to one that ends up in a file on disk. you can supply another output stream that ends up in the zip.
if you look at the code in the example you gave about appending files to zip, you see the following:
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(source));
for(int i = 0; i < files.length; i++){
InputStream in = new FileInputStream(files[i]);
out.putNextEntry(new ZipEntry(path + files[i].getName()));
for(int read = in.read(buffer); read > -1; read = in.read(buffer)){
out.write(buffer, 0, read);
}
out.closeEntry();
in.close();
}
...
out.close();
what is happening ? a zip output stream is opened, named "out". then a loop is performed on the files. for each file, an input stream is obtained to read the file bytes, named "in". then an entry is added into the the zip output stream. adding it prepares the output stream to receive data for that entry. after that, the input stream is written into the output stream, the entry is closed (in prparation for the next one for the next file in the loop) and in the end the zip output stream is closed.
well, all you have to do is to loop over your documents (currently being in "m_objectToWrite") instead of the disk files. and then, instead of copying from an input stream to an output stream, you ask your xml outputter to write the document to the output stream. pretty much the same concept of "in a logical world, bytes go from input to output". But here, instead of manually doing this copy, some special object is doing it for you. the xml outputter.
I will leave to you to get everything to work correctly, like a good path and where files are stored in the zip. but supposing that m_objectToWrite is a "Document" object, a skeleton for a working code could be : (using code from the above and from your code in this post:
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(source));
for( Document m_objectToWrite : MY_DOCUMENTS_LIST ){
out.putNextEntry(new ZipEntry(path + GIVE_NAME_BASED_ON_CURRENT_DOCUMENT));
objOut.output(m_objectToWrite.toXml(0), out);
out.closeEntry();
}
...
out.close();