ASCII: Difference between revisions
No edit summary |
No edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
See [[Example Configuration]] for more information on the ASCII Input option. | [[Category: Middleware4j]] | ||
See [[Middleware4j Example Configuration|Example Configuration]] for more information on the ASCII Input option. | |||
The ASCII Connector can be used for input and output. | The ASCII Connector can be used for input and output. | ||
<syntaxhighlight lang="xml"> | |||
<map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML"> | |||
<input id="in1" description="Read ASCII Flat File"> | |||
<type>ASCII</type> | |||
<path>./interface/input/Map02 ASCII to XML</path> | |||
<mask/> | |||
<inputPattern>1-4,18-21</inputPattern> | |||
<pollingInterval>1000</pollingInterval> | |||
<XSLT>Map02_ASCII_to_XML.xsl</XSLT> | |||
</input> | |||
<output id="out1" enabled="Y" description="Write XML"> | |||
<path>./interface/output/Map02 ASCII to XML</path> | |||
<type>XML</type> | |||
<XSLT/> | |||
</output> | |||
</map> | |||
</syntaxhighlight> | |||
===ASCII Input Map Configuration=== | ===ASCII Input Map Configuration=== | ||
'''config.xml''' | '''config.xml''' | ||
<syntaxhighlight lang="xml"> | |||
<map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML"> | <map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML"> | ||
<input id="in1" description="Read ASCII Flat File"> | <input id="in1" description="Read ASCII Flat File"> | ||
Line 21: | Line 40: | ||
</output> | </output> | ||
</map> | </map> | ||
</syntaxhighlight> | |||
The unique setting which is important above is the `<inputPattern>1-4,18-21</inputPattern>`. This determines the columns within the input file which are to be read into memory and optionally processed by the XSLT Style Sheet. | The unique setting which is important above is the `<inputPattern>1-4,18-21</inputPattern>`. This determines the columns within the input file which are to be read into memory and optionally processed by the XSLT Style Sheet. | ||
Line 27: | Line 47: | ||
===ASCII Map Output Configuration=== | ===ASCII Map Output Configuration=== | ||
<syntaxhighlight lang="xml"> | |||
<map id="Map09" enabled="Y" description="XML to ASCII Flat File"> | <map id="Map09" enabled="Y" description="XML to ASCII Flat File"> | ||
<input id="in1" description="Read XML File"> | <input id="in1" description="Read XML File"> | ||
Line 43: | Line 63: | ||
</output> | </output> | ||
</map> | </map> | ||
</syntaxhighlight> | |||
The output connector is very similar to configure and in this example we use a XSL file called to create a Flat ASCII file from a standard Commander4j XML message. The XSL source in this example looks like this. In this scenario we want to extract and export the order, material and description from the xml and write to a flat ascii file. We are going to write the data to 3 column ranges define in `<outputPattern>1-10,12-21,23-53</outputPattern>` | The output connector is very similar to configure and in this example we use a XSL file called to create a Flat ASCII file from a standard Commander4j XML message. The XSL source in this example looks like this. In this scenario we want to extract and export the order, material and description from the xml and write to a flat ascii file. We are going to write the data to 3 column ranges define in `<outputPattern>1-10,12-21,23-53</outputPattern>` | ||
Line 49: | Line 69: | ||
===Sample XSL File=== | ===Sample XSL File=== | ||
'''Map09_XML_to_ASCII.xsl''' | '''Map09_XML_to_ASCII.xsl''' | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
Line 82: | Line 102: | ||
</xsl:template> | </xsl:template> | ||
</xsl:stylesheet> | </xsl:stylesheet> | ||
</syntaxhighlight> | |||
The above style sheet creates a intermediate XML file which is then passed to the ASCII connector to write the flat file. It is important to match the number of columns extracted with the XSL to the number of columns defined in the output connector. You will notice that the XSL includes some functions. The description for example uses a function to remove commas. You can find more information regardin these functions in [[XSLT Extension Functions]] | The above style sheet creates a intermediate XML file which is then passed to the ASCII connector to write the flat file. It is important to match the number of columns extracted with the XSL to the number of columns defined in the output connector. You will notice that the XSL includes some functions. The description for example uses a function to remove commas. You can find more information regardin these functions in [[XSLT Extension Functions]] | ||
Line 89: | Line 110: | ||
===Sample XML Input File (Commander4j Production Declaration message)=== | ===Sample XML Input File (Commander4j Production Declaration message)=== | ||
'''XML to ASCII Flat File 1.xml''' | '''XML to ASCII Flat File 1.xml''' | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<message> | <message> | ||
Line 130: | Line 151: | ||
</messageData> | </messageData> | ||
</message> | </message> | ||
</syntaxhighlight> | |||
===Intermediate XML (result of appling XSL to input XML message)=== | ===Intermediate XML (result of appling XSL to input XML message)=== | ||
<syntaxhighlight lang="xml"> | |||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
<data cols="15" rows="1" type="CSV"> | <data cols="15" rows="1" type="CSV"> | ||
Line 154: | Line 176: | ||
</row> | </row> | ||
</data> | </data> | ||
</syntaxhighlight> | |||
When the XSL executed against the input XML the above intermediate file is created. This is then passed to the output connector which matches the data found in the xml above to the column definitions. | When the XSL executed against the input XML the above intermediate file is created. This is then passed to the output connector which matches the data found in the xml above to the column definitions. | ||
Line 159: | Line 182: | ||
===Output ASCII=== | ===Output ASCII=== | ||
20725187 43170672 Self Sealing Stem Bolt | <syntaxhighlight lang="Plaintext"> | ||
20725187 43170672 Self Sealing Stem Bolt | |||
</syntaxhighlight> | |||
This is the output from the transformation. The intermediate files can be found in the interface/log directory. For more information see the | This is the output from the transformation. The intermediate files can be found in the interface/log directory. For more information see the [[Middleware4j Example Configuration|Example Configuration]] |
Latest revision as of 10:25, 25 August 2024
See Example Configuration for more information on the ASCII Input option.
The ASCII Connector can be used for input and output.
<map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML"> <input id="in1" description="Read ASCII Flat File"> <type>ASCII</type> <path>./interface/input/Map02 ASCII to XML</path> <mask/> <inputPattern>1-4,18-21</inputPattern> <pollingInterval>1000</pollingInterval> <XSLT>Map02_ASCII_to_XML.xsl</XSLT> </input> <output id="out1" enabled="Y" description="Write XML"> <path>./interface/output/Map02 ASCII to XML</path> <type>XML</type> <XSLT/> </output> </map>
ASCII Input Map Configuration
config.xml
<map id="Map02" enabled="Y" description="ASCII File Fixed Column to XML"> <input id="in1" description="Read ASCII Flat File"> <type>ASCII</type> <path>./interface/input/Map02 ASCII to XML</path> <mask/> <inputPattern>1-4,18-21</inputPattern> <pollingInterval>1000</pollingInterval> <XSLT>Map02_ASCII_to_XML.xsl</XSLT> </input> <output id="out1" enabled="Y" description="Write XML"> <path>./interface/output/Map02 ASCII to XML</path> <type>XML</type> <XSLT/> </output> </map>
The unique setting which is important above is the `<inputPattern>1-4,18-21</inputPattern>`. This determines the columns within the input file which are to be read into memory and optionally processed by the XSLT Style Sheet.
The above scenario is documented in some detail within the Example Configuration page.
ASCII Map Output Configuration
<map id="Map09" enabled="Y" description="XML to ASCII Flat File"> <input id="in1" description="Read XML File"> <type>XML</type> <path>./interface/input/Map09 XML to ASCII</path> <mask/> <pollingInterval>1000</pollingInterval> <XSLT>Map09_XML_to_ASCII.xsl</XSLT> </input> <output id="out1" enabled="Y" description="Write ASCII File"> <path>./interface/output/Map09 XML to ASCII</path> <type>ASCII</type> <outputPattern>1-10,12-21,23-53</outputPattern> <XSLT/> </output> </map>
The output connector is very similar to configure and in this example we use a XSL file called to create a Flat ASCII file from a standard Commander4j XML message. The XSL source in this example looks like this. In this scenario we want to extract and export the order, material and description from the xml and write to a flat ascii file. We are going to write the data to 3 column ranges define in `<outputPattern>1-10,12-21,23-53</outputPattern>`
Sample XSL File
Map09_XML_to_ASCII.xsl
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:c4j="http://www.commander4j.com" xmlns:c4j_XSLT_Ext="http://com.commander4j.Transformation" exclude-result-prefixes="xs c4j c4j_XSLT_Ext" version="2.0"> <xsl:output encoding="UTF-8" indent='yes' method="xml" /> <xsl:strip-space elements="*"/> <xsl:template match="text() | @*"/> <xsl:variable name="sscc" select="/message/messageData[1]/productionDeclaration[1]/SSCC"/> <xsl:template match="message/messageData/productionDeclaration"> <data cols="15" rows="1" type="CSV"> <row id="1"> <col id="1"><xsl:value-of select="processOrder"/></col> <col id="2"><xsl:value-of select="material"/></col> <col id="3"><xsl:value-of select="c4j_XSLT_Ext:removeCommas(description)"/></col> <col id="4"><xsl:value-of select="floor(number(productionQuantity))"/></col> <col id="5"><xsl:value-of select='name' /></col> <col id="6"><xsl:value-of select="c4j_XSLT_Ext:formatDate(productionDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')"/></col> <col id="7"><xsl:value-of select="batch"/></col> <col id="8"><xsl:value-of select="SSCC"/></col> <col id="9"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')" /></col> <col id="10"><xsl:value-of select="warehouse"/></col> <col id="11"><xsl:value-of select="storageLocation"/></col> <col id="12"><xsl:value-of select="c4j_XSLT_Ext:formatDate(expiryDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')" /></col> <col id="13"><xsl:value-of select="c4j_XSLT_Ext:formatDate(productionDate, 'yyyy-MM-dd''T''HH:mm', 'dd-MMM-yyyy')"/></col> <col id="14"><xsl:value-of select="old_code"/></col> <col id="15"><xsl:value-of select="c4j_XSLT_Ext:subString($sscc, 8, 9)"/></col> </row> </data> </xsl:template> </xsl:stylesheet>
The above style sheet creates a intermediate XML file which is then passed to the ASCII connector to write the flat file. It is important to match the number of columns extracted with the XSL to the number of columns defined in the output connector. You will notice that the XSL includes some functions. The description for example uses a function to remove commas. You can find more information regardin these functions in XSLT Extension Functions
Lets work through the sample files to understand what is happening here.
Sample XML Input File (Commander4j Production Declaration message)
XML to ASCII Flat File 1.xml
<?xml version="1.0" encoding="UTF-8"?> <message> <hostRef>service</hostRef> <messageRef>12584314</messageRef> <interfaceType>Production Declaration</interfaceType> <messageInformation>SSCC=000000000000000123</messageInformation> <interfaceDirection>Output</interfaceDirection> <messageDate>2016-08-01T14:58:16</messageDate> <messageData> <productionDeclaration> <SSCC>000000000000000123</SSCC> <processOrder>20725187</processOrder> <recipe>100000000028949253</recipe> <requiredResource>P2VK1112</requiredResource> <material>43170672</material> <description>Self Sealing Stem Bolt</description> <old_code/> <ean>07613032213848</ean> <variant>00</variant> <status>Unrestricted</status> <batch>6214093310</batch> <batchStatus>Restricted</batchStatus> <expiry_Mode>BATCH</expiry_Mode> <expiryDate>2018-08-31T00:00:00</expiryDate> <location>EARTH</location> <name>Earth</name> <gln>5000161800292</gln> <plant>0933</plant> <warehouse>734</warehouse> <storageLocation>0001</storageLocation> <storageSection/> <storageBin>DESPATCH</storageBin> <storageType>PRO</storageType> <productionQuantity>5616.000</productionQuantity> <productionUOM>EA</productionUOM> <confirmed>Y</confirmed> <productionDate>2016-08-01T14:58:03</productionDate> </productionDeclaration> </messageData> </message>
Intermediate XML (result of appling XSL to input XML message)
<?xml version="1.0" encoding="UTF-8"?> <data cols="15" rows="1" type="CSV"> <row id="1"> <col id="1">20725187</col> <col id="2">43170672</col> <col id="3">Self Sealing Stem Bolt</col> <col id="4">5616</col> <col id="5">Earth</col> <col id="6">01-Aug-2016</col> <col id="7">6214093310</col> <col id="8">000000000000000123</col> <col id="9">31-Aug-2018</col> <col id="10">734</col> <col id="11">0001</col> <col id="12">31-Aug-2018</col> <col id="13">01-Aug-2016</col> <col id="14"/> <col id="15">000000012</col> </row> </data>
When the XSL executed against the input XML the above intermediate file is created. This is then passed to the output connector which matches the data found in the xml above to the column definitions.
Output ASCII
20725187 43170672 Self Sealing Stem Bolt
This is the output from the transformation. The intermediate files can be found in the interface/log directory. For more information see the Example Configuration