CSV: Difference between revisions
No edit summary |
No edit summary |
||
(12 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category: Middleware4j]] | |||
=CSV Map Configuration= | =CSV Map Configuration= | ||
'''config.xml''' | '''config.xml''' | ||
<syntaxhighlight lang="xml"> | |||
<map id="Map04" enabled="Y" description="GEN Comma Separated Variables"> | <map id="Map04" enabled="Y" description="GEN Comma Separated Variables"> | ||
<input id="in1" description="Read GEN Comma Separated Variables"> | <input id="in1" description="Read GEN Comma Separated Variables"> | ||
Line 19: | Line 19: | ||
</output> | </output> | ||
</map> | </map> | ||
</syntaxhighlight> | |||
The CSV input connector uses the OpenCSV library and requires very little configuration. The are a pair of settings which you should review | The CSV input connector uses the OpenCSV library and requires very little configuration. The are a pair of settings which you should review | ||
<syntaxhighlight lang="xml"> | |||
<optionDelimeter>^</optionDelimeter> | <optionDelimeter>^</optionDelimeter> | ||
</syntaxhighlight> | |||
and | and | ||
<syntaxhighlight lang="xml"> | |||
<csvOptions>separator=,^quote="</csvOptions> | <csvOptions>separator=,^quote="</csvOptions> | ||
</syntaxhighlight> | |||
In the <csvOptions>separator=,^quote="</csvOptions> element you will see that 2 values are set, '''separator''' and '''quote'''. These 2 settings are separated by a delimiter which happens to be **^** in this example. However if by some unfortunate coincedence your CSV file uses that character as a value separater then you might need to use a different delimited in the configuration - which is where the `<optionDelimeter>^</optionDelimeter>` can be used. | In the <csvOptions>separator=,^quote="</csvOptions> element you will see that 2 values are set, '''separator''' and '''quote'''. These 2 settings are separated by a delimiter which happens to be **^** in this example. However if by some unfortunate coincedence your CSV file uses that character as a value separater then you might need to use a different delimited in the configuration - which is where the `<optionDelimeter>^</optionDelimeter>` can be used. | ||
[[file:delimiter.png]] | [[file:delimiter.png|link=|400px]] | ||
NOTE that if you don't want a quote character this should be represented as shown below | NOTE that if you don't want a quote character this should be represented as shown below | ||
with '''_none_''' used as the value. | with '''_none_''' used as the value. | ||
<syntaxhighlight lang="xml"> | |||
<csvOptions>separator=,^quote=none</csvOptions> | <csvOptions>separator=,^quote=none</csvOptions> | ||
</syntaxhighlight> | |||
=CSV Output Configuration= | =CSV Output Configuration= | ||
<syntaxhighlight lang="xml"> | |||
<map id="map211i" enabled="Y" | <map id="map211i" enabled="Y" | ||
description="Commander4j Production Declaration to CSV"> | description="Commander4j Production Declaration to CSV"> | ||
Line 58: | Line 66: | ||
</output> | </output> | ||
</map> | </map> | ||
</syntaxhighlight> | |||
{| class="wikitable" style="margin:auto" | |||
|+ System Keys | |||
|- | |||
! Element !! Value !! Description | |||
|- | |||
| style="width: 150px"|path || style="width: 90px"|Path || Specifies where output files are saved. | |||
|- | |||
| type || CSV || Specify the output file format | |||
|- | |||
| optionDelimeter || char || See earlier description. | |||
|- | |||
| csvOptions || var=val || See earlier description. | |||
|- | |||
| outputFileExtension || Blank or ext || File extension to use for output file. | |||
|- | |||
| prefix || String || Option to force all output files to begin with a specific string prefix | |||
|- | |||
| use83GUID || Y or N || For backwards compatibility with legacy apps which don't support long filenames. Generates a filename in 8.3 format | |||
|- | |||
| XSLT || filename || Not used | |||
|} | |||
=CSV Example Input= | =CSV Example Input= | ||
'''GEN Comma Separated Variables 1.csv''' | '''GEN Comma Separated Variables 1.csv''' | ||
01050213060215701000123780990210133980001,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 | 01050213060215701000123780990210133980001,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 | ||
01050213060215701000123780990210133980002,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 | 01050213060215701000123780990210133980002,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 | ||
Line 80: | Line 100: | ||
=CSV to XML Intermediate Format= | =CSV to XML Intermediate Format= | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<data cols="10" filename="GEN Comma Separated Variables 1.csv" rows="5" type="CSV"> | <data cols="10" filename="GEN Comma Separated Variables 1.csv" rows="5" type="CSV"> | ||
Line 144: | Line 164: | ||
</row> | </row> | ||
</data> | </data> | ||
</syntaxhighlight> | |||
=XML Example Output from XSLT= | =XML Example Output from XSLT= | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<test> | <test> | ||
Line 155: | Line 176: | ||
<barcode>01050213060215701000123780990210133980005</barcode> | <barcode>01050213060215701000123780990210133980005</barcode> | ||
</test> | </test> | ||
</syntaxhighlight> |
Latest revision as of 16:58, 27 August 2024
CSV Map Configuration
config.xml
<map id="Map04" enabled="Y" description="GEN Comma Separated Variables"> <input id="in1" description="Read GEN Comma Separated Variables"> <type>CSV</type> <path>./interface/input/403 (GEN Comma Separated Variables)</path> <mask/> <pollingInterval>1000</pollingInterval> <XSLT>CSV_to_XML_Example.xsl</XSLT> <optionDelimeter>^</optionDelimeter> <csvOptions>separator=,^quote="</csvOptions> </input> <output id="out1" enabled="Y" description="Write XML Example"> <path>./interface/output/403 (GEN XML)</path> <type>XML</type> <XSLT/> </output> </map>
The CSV input connector uses the OpenCSV library and requires very little configuration. The are a pair of settings which you should review
<optionDelimeter>^</optionDelimeter>
and
<csvOptions>separator=,^quote="</csvOptions>
In the <csvOptions>separator=,^quote="</csvOptions> element you will see that 2 values are set, separator and quote. These 2 settings are separated by a delimiter which happens to be **^** in this example. However if by some unfortunate coincedence your CSV file uses that character as a value separater then you might need to use a different delimited in the configuration - which is where the `<optionDelimeter>^</optionDelimeter>` can be used.
NOTE that if you don't want a quote character this should be represented as shown below with _none_ used as the value.
<csvOptions>separator=,^quote=none</csvOptions>
CSV Output Configuration
<map id="map211i" enabled="Y" description="Commander4j Production Declaration to CSV"> <input id="in1" description="Read C4J XML File"> <type>XML</type> <path>./interface/input/C4J Production Declaration</path> <mask/> <pollingInterval>1000</pollingInterval> <XSLT>C4J_PRODDEC_XML_to_CSV.xsl</XSLT> </input> <output id="out1" enabled="Y" description="Write CSV"> <path>./interface/output/CSV Output</path> <type>CSV</type> <optionDelimeter>^</optionDelimeter> <csvOptions>separator=,^quote="</csvOptions> <outputFileExtension>csv</outputFileExtension> <prefix>X</prefix> <use83GUID>Y</use83GUID> <XSLT/> </output> </map>
Element | Value | Description |
---|---|---|
path | Path | Specifies where output files are saved. |
type | CSV | Specify the output file format |
optionDelimeter | char | See earlier description. |
csvOptions | var=val | See earlier description. |
outputFileExtension | Blank or ext | File extension to use for output file. |
prefix | String | Option to force all output files to begin with a specific string prefix |
use83GUID | Y or N | For backwards compatibility with legacy apps which don't support long filenames. Generates a filename in 8.3 format |
XSLT | filename | Not used |
CSV Example Input
GEN Comma Separated Variables 1.csv
01050213060215701000123780990210133980001,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 01050213060215701000123780990210133980002,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 01050213060215701000123780990210133980003,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 01050213060215701000123780990210133980004,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780 01050213060215701000123780990210133980005,150213061500000017,15,15000,0210133,5021306021570,1008369,LS 2D BLU,1000,00123780
CSV to XML Intermediate Format
<?xml version="1.0" encoding="UTF-8"?> <data cols="10" filename="GEN Comma Separated Variables 1.csv" rows="5" type="CSV"> <row id="1"> <col id="1">01050213060215701000123780990210133980001</col> <col id="2">150213061500000017</col> <col id="3">15</col> <col id="4">15000</col> <col id="5">0210133</col> <col id="6">5021306021570</col> <col id="7">1008369</col> <col id="8">LS 2D BLU</col> <col id="9">1000</col> <col id="10">00123780</col> </row> <row id="2"> <col id="1">01050213060215701000123780990210133980002</col> <col id="2">150213061500000017</col> <col id="3">15</col> <col id="4">15000</col> <col id="5">0210133</col> <col id="6">5021306021570</col> <col id="7">1008369</col> <col id="8">LS 2D BLU</col> <col id="9">1000</col> <col id="10">00123780</col> </row> <row id="3"> <col id="1">01050213060215701000123780990210133980003</col> <col id="2">150213061500000017</col> <col id="3">15</col> <col id="4">15000</col> <col id="5">0210133</col> <col id="6">5021306021570</col> <col id="7">1008369</col> <col id="8">LS 2D BLU</col> <col id="9">1000</col> <col id="10">00123780</col> </row> <row id="4"> <col id="1">01050213060215701000123780990210133980004</col> <col id="2">150213061500000017</col> <col id="3">15</col> <col id="4">15000</col> <col id="5">0210133</col> <col id="6">5021306021570</col> <col id="7">1008369</col> <col id="8">LS 2D BLU</col> <col id="9">1000</col> <col id="10">00123780</col> </row> <row id="5"> <col id="1">01050213060215701000123780990210133980005</col> <col id="2">150213061500000017</col> <col id="3">15</col> <col id="4">15000</col> <col id="5">0210133</col> <col id="6">5021306021570</col> <col id="7">1008369</col> <col id="8">LS 2D BLU</col> <col id="9">1000</col> <col id="10">00123780</col> </row> </data>
XML Example Output from XSLT
<?xml version="1.0" encoding="UTF-8"?> <test> <barcode>01050213060215701000123780990210133980001</barcode> <barcode>01050213060215701000123780990210133980002</barcode> <barcode>01050213060215701000123780990210133980003</barcode> <barcode>01050213060215701000123780990210133980004</barcode> <barcode>01050213060215701000123780990210133980005</barcode> </test>