To export a report to XML

  1. Create a new XMLExportFormatOptions object.
    XMLExportFormat xmlExportFormat = new XMLExportFormat();
    XMLExportFormats xmlExportFormats = new XMLExportFormats();
    IXMLExportFormatOptions xmlExportFormatOptions = new XMLExportFormatOptions();
  2. Use the PrintOutputController class to get the list of XML export format types saved with the report.
    xmlExportFormats = rcd.getPrintOutputController().getSavedXMLExportFormats();
    int index = xmlExportFormats.getDefaultExportSelection();
    xmlExportFormatOptions.setXMLExportSelection(index);
    xmlExportFormat = xmlExportFormats.getXMLExportFormat(index);
  3. Create an XMLExportFormatOptions object and set the export format type to XML.
    IExportOptions expOpts = new ExportOptions();
    expOpts.setExportFormatType(ReportExportFormat.XML);
  4. Apply the XML export options.
    expOpts.setFormatOptions(xmlExportFormatOptions);
  5. Create a new file with the specified path, name, and file extension.
    String xmlPath = "C:\\" + rcd.displayName() + "_" + xmlExportFormat.getName() + "." + xmlExportFormat.getFileExtension();
    FileOutputStream fos = new FileOutputStream(xmlPath);
  6. Create a new ByteArrayInputStream object, streams the file using the Write method, and closes the stream.
    ByteArrayInputStream byteIS = (ByteArrayInputStream)rcd.getPrintOutputController().export(expOpts);
    byte[] buf = new byte[2000 *1024];
            
    int nRead = 0;
    while ((nRead = byteIS.read(buf)) != -1)
    {
       fos.write(buf, 0, nRead); 
    }
           
    fos.close();
Example: 
void exportToXML(ReportClientDocument rcd) throws ReportSDKException, FileNotFoundException, IOException
{  
  IXMLExportFormat xmlExportFormat = new XMLExportFormat();
  XMLExportFormats xmlExportFormats = new XMLExportFormats();
  IXMLExportFormatOptions xmlExportFormatOptions = new XMLExportFormatOptions();
        
  xmlExportFormats = rcd.getPrintOutputController().getSavedXMLExportFormats();
  int index = xmlExportFormats.getDefaultExportSelection();
  xmlExportFormatOptions.setXMLExportSelection(index);
  xmlExportFormat = xmlExportFormats.getXMLExportFormat(index);
        
  IExportOptions expOpts = new ExportOptions();
  expOpts.setExportFormatType(ReportExportFormat.XML);
  expOpts.setFormatOptions(xmlExportFormatOptions);
        
  String xmlPath = "C:\\" + rcd.displayName() + "_" + xmlExportFormat.getName() + "." + xmlExportFormat.getFileExtension();
  FileOutputStream fos = new FileOutputStream(xmlPath);

  ByteArrayInputStream byteIS = (ByteArrayInputStream)rcd.getPrintOutputController().export(expOpts);
  byte[] buf = new byte[2000 *1024];
        
  int nRead = 0;
  while ((nRead = byteIS.read(buf)) != -1)
  {
     fos.write(buf, 0, nRead); 
  }
       
  fos.close();
}
This list includes the classes used by the sample code:
  • com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
  • com.crystaldecisions.sdk.occa.report.exportoptions.IExportOptions
  • com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions
  • com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat
  • com.crystaldecisions.sdk.occa.report.exportoptions.IXMLExportFormat
  • com.crystaldecisions.sdk.occa.report.exportoptions.XMLExportFormat
  • com.crystaldecisions.sdk.occa.report.exportoptions.XMLExportFormats
  • com.crystaldecisions.sdk.occa.report.exportoptions.IXMLExportFormatOptions
  • com.crystaldecisions.sdk.occa.report.exportoptions.XMLExportFormatOptions
  • com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
  • java.io.ByteArrayInputStream
  • java.io.FileNotFoundException
  • java.io.FileOutputStream
  • java.io.IOException