@ComponentProfile(summary="Easily transform a document from CSV to XML", tag="service,transform,csv,xml") public class RawCsvToXmlTransformService extends CsvToXmlServiceImpl
CSVParser
.
This transformation uses commons-csv as the parsing engine for a CSV
file. Basic parsing options are supported : DEFAULT
,
EXCEL
, RFC4180
,
MYSQL
and TAB DELIMITED
which correspond to
the base formats defined by CSVFormat
. Custom CSV formats are provided via CustomFormatBuilder
.
This service does not attempt to make parsing decisions, so CSV files that have differing number of columns on each line would be perfectly acceptable.
For example, given an input document :
HEADER,19052017
PRODUCT-CODE,BARCODE,DP,PROMPRICE,DISCOUNT,INSTOCK,REPORT,REPORT-DATE,SOURCE
XXXXXXXX,1234567890123,2.75,0.00,5.00,2,,,GSL
TRAILER,4
Then the output would be
<csv-xml>
<record>
<csv-field-1>HEADER<csv-field-1>
<csv-field-2>19052017</csv-field-2>
</record>
<record>
<csv-field-1>PRODUCT-CODE<csv-field-1>
<csv-field-2>BARCODE</csv-field-2>
<csv-field-3>DP</csv-field-3>
<csv-field-4>PROMPRICE</csv-field-4>
<csv-field-5>DISCOUNT</csv-field-5>
<csv-field-6>INSTOCK</csv-field-6>
<csv-field-7>REPORT</csv-field-7>
<csv-field-8>REPORT-DATE</csv-field-8>
<csv-field-9>SOURCE</csv-field-9>
</record>
<record>
<csv-field-1>XXXXXXXX<csv-field-1>
<csv-field-2>1234567890123</csv-field-2>
<csv-field-3>,2.75</csv-field-3>
<csv-field-4>0.00</csv-field-4>
<csv-field-5>5.00</csv-field-5>
<csv-field-6>2</csv-field-6>
<csv-field-7></csv-field-7>
<csv-field-8></csv-field-8>
<csv-field-9>GSL</csv-field-9>
</record>
<record>
<csv-field-1>TRAILER<csv-field-1>
<csv-field-2>4</csv-field-2>
</record>
</csv-xml>
Because there is no verification that the CSV columns matchup; if the message type isn't a CSV (e.g. it's JSON or XML), then it will still be marked up into XML, so take that into account when using this as part of a workflow. Behaviour with rogue messages may not be as you expect.
In the adapter configuration file this class is aliased as raw-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 |
---|
RawCsvToXmlTransformService() |
RawCsvToXmlTransformService(FormatBuilder f) |
Modifier and Type | Method and Description |
---|---|
protected org.w3c.dom.Document |
transform(AdaptrisMessage msg) |
addNewElement, createTextNode, doService, getFormat, getStripIllegalXmlChars, setFormat, setStripIllegalXmlChars, stripIllegalXmlChars, writeXmlDocument
closeService, evaluateEncoding, getIncludeLineNumberAttribute, getOutputMessageEncoding, includeLineNumberAttribute, initService, prepare, 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 RawCsvToXmlTransformService()
public RawCsvToXmlTransformService(FormatBuilder f)
protected org.w3c.dom.Document transform(AdaptrisMessage msg) throws ServiceException
transform
in class CsvToXmlServiceImpl
ServiceException