Example: Mapping UN/EDIFACT to XML
This example shows how to map data from UN/EDIFACT messages to an XML schema, in order to produce an XML instance file for further processing. The mapping created in this example is available at the following path: <Documents>\Altova\MapForce2023\MapForceExamples\EDI_Order.mfd.
Step 1: Add the UN/EDIFACT component to the mapping
1.Create a new mapping and select one of the following transformation languages: Java, C#, C++, or BUILT-IN. In this example, Java is selected as transformation language.
2.On the Insert menu, click EDI.
3.On the EDI collections dialog box, select the EDIFACT collection, then select the ORDERS message type, and click OK.
4.When prompted to supply a sample EDI file, click Browse and open the ORDERS.EDI file from the <Documents>\Altova\MapForce2023\MapForceExamples\ directory. After you open the file, the Component Settings dialog box opens. This enables you to review the settings of the EDI component before adding it to the mapping. You can change these settings at any time later if required (see EDI Component Settings). Notice that the ORDERS.EDI file appears as Input EDI file.
5.Click OK. The EDI component is now displayed in the mapping area. Double-click the Message_ORDERS node to view its child items. To resize the component, click and drag the lower-right corner of the component window.
Step 2: Add the target schema component to the mapping
1.On the Insert menu, click XML Schema/File, and open the Order.xsd file from the <Documents>\Altova\MapForce2023\MapForceExamples\ directory.
2.When prompted to supply a sample XML file, click Skip and select Order as the root of the target document.
At this point, both the source EDI component and the target XML schema are on the mapping area, so we are ready to start drawing the mapping connections.
Step 3: Map the EDI items
The EDI component displays the structure of a message based on the collection (ORDERS) we selected. Typically, not all of the nodes will actually contain data, so you must be sufficiently familiar with the EDI documents being worked on, to locate the relevant nodes.
In MapForce, you map a source item and a target item by drawing a connection between them. For step-by-step instructions on how to create mapping connections in MapForce, see Working with Connections.
In this example, the following nodes (starting from the Group/Message_ORDERS node) will be mapped (connected) first:
At this stage, the mapping should look similar to the image below:
Continue the mapping process and map:
Step 4: Format the date
Drag the to-datetime function from the edifact library into the Mapping area, see also Add a Function to the Mapping.
By supplying as arguments to this function the F2380 and F2379 components of the DTM/C507 element, we can create an appropriately formatted Received datetime.
We therefore map the following fields:
The F2380 input of the to-datetime function
The F2379 input of the to-datetime function
The result of the to-datetime function
Step 5: Filter the buyer purchase orders
At this point we want to filter the "Buyer" purchase orders. These can be identified by the party function code qualifier of the NAD (Name and address) segment. In this case, the value 'BY' indicates a "Buyer" (Party to whom merchandise and/or service is sold).
1.Drag the equal function from the core library into the Mapping area.
2.Add a filter to the mapping (On the Insert menu, click Filter: Nodes/Rows).
3.Add a constant to the mapping (On the Insert menu, click Constant). Assign to the constant the value "BY" by entering "BY" into the text field:
Map the following items:
The b input of the equal function
The constant "BY"
The a input of the equal function
The result of the equal function
The bool input of the filter component
The node/row input of the filter component
The on-true result of the filter component
Order/Customer in the schema
The aim here is to only map data if the NAD node refers to a 'Buyer', as identified by the party function code qualifier 'BY'.
Step 6: Calculate pricing and tax
The final step in this task is to calculate the pricing and tax costs.
1.From the Libraries window, drag two multiply and one divide function (of the core library) into the Mapping area.
2.Insert a Constant component (Insert | Constant). Make sure "Number" is selected as type, and enter 100.0 into the text field.
3.Map the following items:
value1 of the first multiply function
value2 of the first multiply function
The result of the first multiply function
value1 of the divide function
The constant "100.0"
value2 of the divide function
The result of the first multiply function
value1 of the second multiply function
The result of divide function
value2 of the second multiply function
The result of the second multiply function
Your mapping should now look like this:
Clicking the output tab performs an "on the fly" transformation and presents you with the XML document result: