I am using Smooks 1.5 and trying to generate an XML File from the EDI-Message I tried also with the standard Plugin, which generates a lof of namespaces, which I couldn't process cause of FreeMaker Template-Engine. This example is without FreeMaker-Engine.
I have a REMADV-message (Format D.01B) which looks like this:
UNA:+.?'
UNB+UNOC:3+4304449000000:14:7611937000723+7610603000005:14+141013:0901+949317133000++REMADV+++EANCOM+1'
UNH+1+REMADV:D:01B:UN:EAN005'
BGM+481+128275+9'
DTM+137:20141011000000:204'
DTM+138:20141017000000:204'
RFF+RA:128275'
RFF+AEK:490359'
PAI+1::42'
NAD+PR+7611937000723::9'
NAD+PE+7610603000005::9+++++++CH'
CUX+2:CHF:11'
DOC+380:::RG+26838'
MOA+12:61.12'
MOA+9:64.17'
MOA+265:-3.05'
MOA+109:-1.28'
DTM+137:20140924000000:204'
DTM+140:20141010000000:204'
...
My question is, how to I have to setup the Mapping-File? Do I need to specify each line or is it enough to only specify the fields which I am interested in?
My mapping file:
--><medi:description name="MESSAGE" version="1.0"/>
<medi:delimiters segment="'!$" field="+" component=":" sub-component="~" />
<medi:segments xmltag="REMADV">
<medi:segment minOccurs="1" maxOccurs="1" segcode="BGM" xmltag="Header">
<medi:field xmltag="Code"/>
<medi:field xmltag="Zahlungsavisnummer"/>
<medi:field xmltag="Code2"/>
</medi:segment>
<medi:segment minOccurs="1" maxOccurs="2" segcode="DTM" xmltag="DATE">
<medi:field xmltag="abc" >
<medi:component xmltag="1"/>
<medi:component xmltag="2"/>
<medi:component xmltag="3"/>
</medi:field>
</medi:segment>
<medi:segmentGroup xmltag="Dataset" maxOccurs="-1">
<medi:segment minOccurs="0" maxOccurs="-1" segcode="DOC" xmltag="Rechnung" truncatable="true">
<medi:field xmltag="Code"/>
<medi:field xmltag="Belegart"/>
<medi:field xmltag="Belegnummer"/>
</medi:segment>
<medi:segment minOccurs="0" maxOccurs="-1" segcode="MOA" xmltag="Rechnung" truncatable="true">
<medi:field xmltag="Code"/>
<medi:field xmltag="TotalAmount"/>
</medi:segment>
</medi:segmentGroup>
<!-- UNT+8+66059903600010' -->
<medi:segment minOccurs="0" segcode="UNT" xmltag="EndsegmentDatensatz"/>
<!-- UNZ+10+00402' -->
<medi:segment minOccurs="0" segcode="UNZ" xmltag="EndsegmentDokument"/>
</medi:segments>
The smooks-config looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.1.xsd">
<!--
Configure the EDI Reader to process the message stream into a stream of SAX events.
-->
<edi:reader mappingModel="REMADV-EDI-To-XML-Mapping.xml"/>
</smooks-resource-list>
The error message is always same:
Must be a minimum of 1 instances of segment [BGM]. Currently at segment number 1.
It looks like that it doesnt find any match Does someone has any idea why I cannot find any field inside the EDI-Message?
Reto
The best way is use the mapping sets generated by Smooks.
smooks-config.xml
And add to your POM the dependency: