XML: Difference between revisions
No edit summary |
Updated by push_wiki.py |
||
| Line 1: | Line 1: | ||
This page is not intended to be a tutorial on XML and XSL, there are many resources online which can do that. This document is designed to illustrate how the middleware application can be used to transform an input XML document into a modified output document. | This page is not intended to be a tutorial on XML and XSL, there are many resources online which can do that. This document is designed to illustrate how the middleware application can be used to transform an input XML document into a modified output document. | ||
The XML connector is perhaps one of the simpler ones to explain. The core middleware application is designed to process data once it has been converted into an xml document internally. For example the CSV and ASCII connectors will load the appropriate file type and convert into XML internally so that you can manipulate the data using XSLT. The XML connector does not need to convert the raw data into XML as it's already in that format when its loaded. | The XML connector is perhaps one of the simpler ones to explain. The core middleware application is designed to process data once it has been converted into an xml document internally. For example the CSV and ASCII connectors will load the appropriate file type and convert into XML internally so that you can manipulate the data using XSLT. The XML connector does not need to convert the raw data into XML as it's already in that format when its loaded. | ||
In the configuration shown below you will see that an | In the configuration shown below you will see that an XSLT transformation is applied in the input stage, however in this example the XSLT could have been applied on the output stage without any effect on the result. | ||
=XML Map Configuration= | =XML Map Configuration= | ||
'''config.xml''' | '''config.xml''' | ||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<map id | <map> | ||
<id>map107</id> | |||
<enabled>true</enabled> | |||
<description>NES C4J Production Declaration to B2MML S95 XML Production Declaration</description> | |||
<enableEmailNotifications>true</enableEmailNotifications> | |||
<connectors> | |||
<input> | |||
<id>in1</id> | |||
<description>Read C4J Prod Dec XML</description> | |||
<type>XML</type> | |||
<url> | |||
<path>./interface/input/advanced/107 (NES C4J Production Declaration)</path> | |||
<mask/> | |||
<prefix/> | |||
<pollingInterval>1000</pollingInterval> | |||
</url> | |||
<xsl> | |||
<XSLTPath/> | |||
<XSLT>C4J_PRODDEC_XML_to_S95_PRODDEC_XML.xsl</XSLT> | |||
</xsl> | |||
</input> | |||
<output> | |||
<id>out1</id> | |||
<enabled>true</enabled> | |||
<description>Write B2MML S95 XML Prod Dec</description> | |||
<type>XML</type> | |||
<url> | |||
<path>./interface/output/advanced/107 (NES B2MML S95 XML Production Declaration)</path> | |||
<prefix/> | |||
<fileExtension/> | |||
<use83GUID>false</use83GUID> | |||
<retainOriginalFilename>false</retainOriginalFilename> | |||
</url> | |||
</output> | |||
</connectors> | |||
</map> | |||
</syntaxhighlight> | </syntaxhighlight> | ||
This map is taken from <code>samples/advanced/config/config.xml</code>. There are no settings particular to the XML connector. As an input it picks up files ending in <code>.xml</code> and passes the document to the style sheet unchanged. As an output it writes whatever XML it is given to a file ending in <code>.xml</code>. | |||
An input file that is not well formed XML cannot be processed. It is renamed with <code>.error</code> on the end and left in the input folder. | |||
=Example Input Document= | =Example Input Document= | ||
| Line 122: | Line 147: | ||
</xsl:stylesheet> | </xsl:stylesheet> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
See also: [[Connectors]], [[Maps]], [[Creating a Map]], [[XSLT Extension Functions]] | |||
[[Category:Middleware4j]] | |||
Latest revision as of 21:47, 9 November 2026
This page is not intended to be a tutorial on XML and XSL, there are many resources online which can do that. This document is designed to illustrate how the middleware application can be used to transform an input XML document into a modified output document.
The XML connector is perhaps one of the simpler ones to explain. The core middleware application is designed to process data once it has been converted into an xml document internally. For example the CSV and ASCII connectors will load the appropriate file type and convert into XML internally so that you can manipulate the data using XSLT. The XML connector does not need to convert the raw data into XML as it's already in that format when its loaded.
In the configuration shown below you will see that an XSLT transformation is applied in the input stage, however in this example the XSLT could have been applied on the output stage without any effect on the result.
XML Map Configuration
config.xml
<map>
<id>map107</id>
<enabled>true</enabled>
<description>NES C4J Production Declaration to B2MML S95 XML Production Declaration</description>
<enableEmailNotifications>true</enableEmailNotifications>
<connectors>
<input>
<id>in1</id>
<description>Read C4J Prod Dec XML</description>
<type>XML</type>
<url>
<path>./interface/input/advanced/107 (NES C4J Production Declaration)</path>
<mask/>
<prefix/>
<pollingInterval>1000</pollingInterval>
</url>
<xsl>
<XSLTPath/>
<XSLT>C4J_PRODDEC_XML_to_S95_PRODDEC_XML.xsl</XSLT>
</xsl>
</input>
<output>
<id>out1</id>
<enabled>true</enabled>
<description>Write B2MML S95 XML Prod Dec</description>
<type>XML</type>
<url>
<path>./interface/output/advanced/107 (NES B2MML S95 XML Production Declaration)</path>
<prefix/>
<fileExtension/>
<use83GUID>false</use83GUID>
<retainOriginalFilename>false</retainOriginalFilename>
</url>
</output>
</connectors>
</map>
This map is taken from samples/advanced/config/config.xml. There are no settings particular to the XML connector. As an input it picks up files ending in .xml and passes the document to the style sheet unchanged. As an output it writes whatever XML it is given to a file ending in .xml.
An input file that is not well formed XML cannot be processed. It is renamed with .error on the end and left in the input folder.
Example Input Document
<?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>WISBECH</location>
<name>Wisbech</name>
<gln>0000000000123</gln>
<plant>1234</plant>
<warehouse>789</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>
Example Output Document
<?xml version="1.0" encoding="UTF-8"?> <ProductionPerformance xmlns:c4j="http://www.commander4j.com"> <ID>12584314</ID> <Plant>1234</Plant> <PublishedDate>2024-04-12T09:39:27</PublishedDate> <ProductionRequestID>20725187</ProductionRequestID> <Recipe>100000000028949253</Recipe> <MaterialDefinitionID>000000000043170672</MaterialDefinitionID> <MaterialLotID>6214093310</MaterialLotID> <MaterialSubLotID>00000000000000000123</MaterialSubLotID> <Plant>1234</Plant> <Warehouse>789</Warehouse> <Type>PRO</Type> <Section/> <Bin>DESPATCH</Bin> <Quantity>5616.000</Quantity> <UnitOfMeasure>EA</UnitOfMeasure> </ProductionPerformance>
XSLT
C4J_PRODDEC_XML_to_S95_PRODDEC_XML.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" exclude-result-prefixes="xs" version="2.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<!-- Local Variables -->
<xsl:variable name="DATENOW" select="current-dateTime()"/>
<xsl:variable name="MESSAGEDATE" select="format-dateTime($DATENOW, '[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01]')"/>
<xsl:template match="message">
<ProductionPerformance>
<ID><xsl:value-of select="/message/messageRef"/></ID>
<Plant><xsl:value-of select="/message/messageData/productionDeclaration/plant"/></Plant>
<PublishedDate><xsl:value-of select="$MESSAGEDATE"/></PublishedDate>
<ProductionRequestID><xsl:value-of select="/message/messageData/productionDeclaration/processOrder"/> </ProductionRequestID>
<Recipe><xsl:value-of select="/message/messageData/productionDeclaration/recipe"/></Recipe>
<MaterialDefinitionID><xsl:value-of select="/message/messageData/productionDeclaration/material"/> </MaterialDefinitionID>
<MaterialLotID><xsl:value-of select="/message/messageData/productionDeclaration/batch"/></MaterialLotID>
<MaterialSubLotID>00<xsl:value-of select="/message/messageData/productionDeclaration/SSCC"/></MaterialSubLotID>
<Plant><xsl:value-of select="/message/messageData/productionDeclaration/plant"/></Plant>
<Warehouse><xsl:value-of select="/message/messageData/productionDeclaration/warehouse"/></Warehouse>
<Type><xsl:value-of select="/message/messageData/productionDeclaration/storageType"/></Type>
<Section><xsl:value-of select="/message/messageData/productionDeclaration/storageSection"/></Section>
<Bin><xsl:value-of select="/message/messageData/productionDeclaration/storageBin"/></Bin>
<Quantity><xsl:value-of select="/message/messageData/productionDeclaration/productionQuantity"/></Quantity>
<UnitOfMeasure><xsl:value-of select="/message/messageData/productionDeclaration/productionUOM"/></UnitOfMeasure>
</ProductionPerformance>
</xsl:template>
</xsl:stylesheet>
See also: Connectors, Maps, Creating a Map, XSLT Extension Functions