@ComponentProfile(summary="Transform CSV to XML using the XML streaming API (STaX).", tag="service,transform,csv,xml", since="3.6.6") public class StreamingCsvToXml extends CsvXmlTransformImpl
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 SimpleCsvToXmlTransformService
. 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.
CSV_FIELD_NAME, CSV_RECORD_NAME, XML_ROOT_ELEMENT
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
StreamingCsvToXml() |
StreamingCsvToXml(PreferenceBuilder prefs,
StreamWriterFactory fact) |
Modifier and Type | Method and Description |
---|---|
protected void |
closeService() |
void |
doService(AdaptrisMessage msg) |
PreferenceBuilder |
getPreferenceBuilder() |
StreamWriterFactory |
getStreamWriter() |
protected void |
initService() |
void |
prepare() |
void |
setPreferenceBuilder(PreferenceBuilder b) |
void |
setStreamWriter(StreamWriterFactory factory)
Set the stream writer factory to use.
|
evaluateEncoding, getIncludeLineNumberAttribute, getOutputMessageEncoding, includeLineNumberAttribute, setIncludeLineNumberAttribute, setOutputMessageEncoding
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsConfirmation, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isConfirmation, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, rethrowServiceException, retrieveComponentState, setContinueOnFail, setIsConfirmation, setIsTrackingEndpoint, setLookupName, setUniqueId, start, stop
public StreamingCsvToXml()
public StreamingCsvToXml(PreferenceBuilder prefs, StreamWriterFactory fact)
public void doService(AdaptrisMessage msg) throws ServiceException
ServiceException
public void prepare() throws CoreException
prepare
in interface ComponentLifecycleExtension
prepare
in class CsvXmlTransformImpl
CoreException
protected void initService() throws CoreException
initService
in class CsvXmlTransformImpl
CoreException
protected void closeService()
closeService
in class CsvXmlTransformImpl
public PreferenceBuilder getPreferenceBuilder()
public void setPreferenceBuilder(PreferenceBuilder b)
public StreamWriterFactory getStreamWriter()
public void setStreamWriter(StreamWriterFactory factory)
factory
- the streamWriterFactory to set, default is DefaultWriterFactory
if not specified.