Class JRXmlExporter

  • All Implemented Interfaces:
    Exporter<ExporterInput,​ReportExportConfiguration,​ExporterConfiguration,​XmlExporterOutput>

    public class JRXmlExporter
    extends JRAbstractExporter<ReportExportConfiguration,​ExporterConfiguration,​XmlExporterOutput,​JRXmlExporterContext>
    Exports a JasperReports document to an XML file that contains the same data as a JasperPrint object, but in XML format, instead of a serialized class. As report templates are defined using the special XML syntax JRXML, the JasperReports library also has a special XML structure for storing generated documents in XML format. This format is called JRPXML because the files produced by the JRXmlExporter usually have the *.jrpxml extension.

    Such XML files can be parsed back into JasperPrint object using the JRPrintXmlLoader utility class. Their structure is validated against an internal XSD file called jasperprint.xsd, that provides the details of the JRPXML structure. Valid JRPXML files should point to the internal XSD file using a public location, as follows:

     <?xml version="1.0" encoding="UTF-8"?>
     <jasperPrint 
       xmlns="http://jasperreports.sourceforge.net/jasperreports/print" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/print http://jasperreports.sourceforge.net/xsd/jasperprint.xsd"
       ...>
     
    The root element of a JRPXML document is <jasperPrint>, which contains a list of report custom properties (<property> tags), a list of element origins (<origin> tags), a list of report style definitions (<style> tags) that are reused by report elements throughout the document, and a list of pages (<page> tags), each of which contains a nested list of elements like lines, rectangles, ellipses, images, and texts.

    The quality of this exporter is equal to the Graphics2D exporter because it preserves 100% of the initial document content and properties. There is no loss in document quality when exporting to XML because the resulting XML content can be loaded back into a JasperPrint object that will look the same as the original one.

    The built-in viewers can display documents exported in JRPXML format because they actually rely on the JRPrintXmlLoader to load the document back into a JasperPrint object before rendering it on the screen.

    Embedding Images

    When exporting XML, pay special attention to how images are stored. The two ways are as follows:
    • If the exporter outputs to a file on disk, it stores the images contained by the source document in separate files that accompany the main JRPXML file. The image files are put in a directory that takes its name from the original destination file name plus the _files suffix, the same directory as the JRPXML file.
    • The exporter can embed images in the JRPXML file itself by encoding their binary data using a Base64 encoder. This simplifies transfer over the network or by direct output to streams.

    To determine how to handle images, set the isEmbeddingImages() exporter output flag, which expects a java.lang.Boolean. By default, the images are embedded in the resulting XML.

    Author:
    Teodor Danciu (teodord@users.sourceforge.net)
    See Also:
    JasperPrint, JRPrintXmlLoader