import voi.vowrite.* ; import java.io.* ; public class SampleCode { public static void main(String args[]) { FileOutputStream fout = null ; try { fout= new FileOutputStream("votable1.xml") ; }catch(FileNotFoundException e){} SampleCode c = new SampleCode() ; c.generateVotable(fout) ; } public void generateVotable(OutputStream oStream) { PrintStream prnStream = new PrintStream(oStream) ; // Create an instance of VOTableStreamingWriter class. VOTableStreamWriter voWrite = new VOTableStreamWriter(prnStream) ; //Create a votable element VOTable vot = new VOTable() ; //Set description of VOTable. String descString = "Inter University Center for Astronomy and Astrophysics(http://www.iucaa.ernet.in)\n Virtual Observatory India(http://vo.iucaa.ernet.in/~voi)\n In case of problems, please contact: voindia@vo.iucaa.ernet.in" ; vot.setDescription(descString) ; // Write the VOTable element to outputStream. voWrite.writeVOTable(vot) ; //Create a new resource element. VOTableResource voResource = new VOTableResource() ; // Write the Resource element to outputStream. voWrite.writeResource(voResource) ; // Create a new Table element VOTableTable voTab = new VOTableTable() ; voTab.setName("Table1") ; // Add two fields in the table. VOTableField voField1 = new VOTableField() ; voField1.setName("Planet"); voField1.setId("field1"); voField1.setDataType("char") ; voField1.setArraySize("10") ; voTab.addField(voField1) ; VOTableField voField2 = new VOTableField() ; voField2.setName("Diameter"); voField2.setId("field2"); voField2.setDataType("int") ; voField2.setWidth("5") ; voTab.addField(voField2) ; VOTableField voField3 = new VOTableField() ; voField3.setName("No Of Satellites"); voField3.setId("field3"); voField3.setDataType("int") ; voField3.setWidth("5") ; voTab.addField(voField3) ; VOTableField voField4 = new VOTableField() ; voField4.setName("Mean Distance From Sun"); voField4.setId("field4"); voField4.setDataType("long"); voField4.setUnit("km") ; voField4.setWidth("15") ; voTab.addField(voField4) ; VOTableGroup group1 = new VOTableGroup(); group1.setName("PlanetInfo"); group1.setId("group1"); VOTableFieldref fieldRef1 = new VOTableFieldref(); fieldRef1.setRef("field1"); VOTableFieldref fieldRef2 = new VOTableFieldref(); fieldRef2.setRef("field2"); group1.addFieldref(fieldRef1); group1.addFieldref(fieldRef2); voTab.addGroup(group1); // Write the Table element to outputStream. voWrite.writeTable(voTab) ; String [] firstRow = {"Mercury", "4880","0","57909175"} ; String [] secondRow = {"Venus", "12112","0","108208930"} ; String [] thirdRow = {"Earth", "12742","1","149597870"} ; // Write the data to outputStream. voWrite.addRow(firstRow, 4) ; voWrite.addRow(secondRow, 4) ; voWrite.addRow(thirdRow, 4) ; // End the TABLE element. voWrite.endTable() ; // End the RESOURCE element. voWrite.endResource() ; // End the VOTABLE element. voWrite.endVOTable() ; } }