Class StreamingCsvToXml

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Transform CSV to XML using the XML streaming API (STaX).",
                      tag="service,transform,csv,xml",
                      since="3.11.0")
    public class StreamingCsvToXml
    extends CsvXmlTransformImpl
    CSV to XML using net.sf.supercsv:super-csv via XMLStreamWriter

    This transformation uses net.sf.supercsv:super-csv as the parsing engine for a CSV file and uses XMLStreamWriter via com.adaptris:interlok-stax to write each row as part of an XML document. It may have better performance characteristics with large CSV files compared to CsvToXml. It also reduces the number of configuration options that are available.

    Element names are always generated from the first line; so a header line is always assumed; Note that if your header rows contains characters that would not be allowed in an standard XML element name then it will be replaced with an '_', so "Order Date" becomes "Order_Date". Additionally illegal XML characters are always stripped (illegal characters would cause an exception regardless in the XMLStreamWriter).

    For example, given an input document :

     
    Event Name,Order Date,Ticket Type,Date Attending,Total Paid
    Glastonbury,"Sep 15, 2012",Free entry,"Jun 26, 2014 at 6:00 PM",0
    Reading Festival,"Sep 16, 2012",Free entry,"Aug 30, 2014 at 6:00 PM",0
     
     
    Then the output (without a header row) would be
     
     <csv-xml>
       <record line="1">
         <Event_Name>Glastonbury</Event_Name>
         <Order_Date>Sep 15, 2012</Order_Date>
         <Ticket_Type>Free entry</Ticket_Type>
         <Date_Attending>Jun 26, 2014 at 6:00 PM</Date_Attending>
         <Total_Paid>0</Total_Paid>
       </record>
       <record line="2">
         <Event_Name>Reading Festival</Event_Name>
         <Order_Date>Sep 16, 2012</Order_Date>
         <Ticket_Type>Free entry</Ticket_Type>
         <Date_Attending>Aug 30, 2014 at 6:00 PM</Date_Attending>
         <Total_Paid>0</Total_Paid>
       </record>
     
     

    In the adapter configuration file this class is aliased as streaming-csv-to-xml-transform which is the preferred alternative to the fully qualified classname when building your configuration.