You may wish to write a VOTable document with a more complicated
structure than a simple VOTABLE/RESOURCE/TABLE one. In this case
you can use the VOSerializer
class which handles only the output of TABLE elements themselves
(the hard part), leaving you free to embed these in whatever XML
superstructure you wish.
Once you have obtained your VOSerializer
by specifying
the table it will serialize and the data format it will use,
you should invoke its
writeFields
method followed by
either
writeInlineDataElement
or
writeHrefDataElement
.
For inline output, the output should be sent to the same stream
to which the XML itself is written. In the latter case however,
you can decide where the streamed data goes, allowing possibilities such
as sending it to a separate file in a location of your choosing,
creating a new MIME attachment to a message, or sending it down
a separate channel to a client. In this case you will need to
ensure that the href associated with it (written into the STREAM element's
href
attribute) will direct a reader to the right place.
Here is an example of how you could write two inline tables in the same RESOURCE element:
void writeTables( StarTable t1, StarTable t2 ) throws IOException { BufferedWriter out = new BufferedWriter( new OutputStreamWriter( System.out ) ); out.write( "<VOTABLE version='1.0'>\n" ); out.write( "<RESOURCE>\n" ); out.write( "<DESCRIPTION>Two tables</DESCRIPTION>\n" ); out.write( "<TABLE>\n" ); VOSerializer ser1 = VOSerializer.makeSerializer( DataFormat.TABLEDATA, t1 ); ser1.writeFields( out ); ser1.writeInlineDataElement( out ); out.write( "</TABLE>\n" ); out.write( "<TABLE>\n" ); VOSerializer ser2 = VOSerializer.makeSerializer( DataFormat.TABLEDATA, t2 ); ser2.writeFields( out ); ser2.writeInlineDataElement( out ); out.write( "</TABLE>\n" ); out.write( "</RESOURCE>\n" ); out.write( "</VOTABLE>\n" ); }and here is how you could write a table with its data streamed to a binary file with a given name (rather than the automatically chosen one selected by
VOTableWriter
):
void writeTable( StarTable table, File binaryFile ) throws IOException { BufferedWriter out = new BufferedWriter( new OutputStreamWriter( System.out ) ); out.write( "<VOTABLE version='1.0'>\n" ); out.write( "<RESOURCE>\n" ); out.write( "<TABLE>\n" ); VOSerializer ser = VOSerializer.makeSerializer( DataFormat.BINARY, table ); ser.writeFields( out ); DataOutputStream binOut = new DataOutputStream( new FileOutputStream( binaryFile ) ); ser.writeHrefDataElement( out, "file:" + binaryFile, binOut ); binOut.close(); out.write( "</TABLE>\n" ); out.write( "<RESOURCE>\n" ); out.write( "<VOTABLE>\n" ); }