我正在使用Smooks 1.5并尝试从EDI-Message生成XML文件 我也尝试使用标准插件,它生成了一小部分命名空间,我无法处理FreeMaker Template-Engine的原因。这个例子没有FreeMaker-Engine。
我有一条REMADV消息(格式D.01B),如下所示:
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'
...
我的问题是,如何设置Mapping-File?我是否需要指定每一行,还是仅仅指定我感兴趣的字段?
我的映射文件:
- &GT;<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>
smooks-config看起来像这样:
<?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>
错误消息始终相同:
Must be a minimum of 1 instances of segment [BGM]. Currently at segment number 1.
看起来它找不到任何匹配 有人知道为什么我在EDI-Message中找不到任何字段吗?
雷托
答案 0 :(得分:0)
最好的方法是使用Smooks生成的映射集。
的Smooks-config.xml中
<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd"
xmlns:xsl="http://www.milyn.org/xsd/smooks/xsl-1.1.xsd"
xmlns:unedifact="http://www.milyn.org/xsd/smooks/unedifact-1.5.xsd">
<unedifact:reader mappingModel="urn:org.milyn.edi.unedifact:d01b-mapping:1.4" ignoreNewLines="true" />
<core:filterSettings type="DOM" />
<core:exports>
<core:result type="org.milyn.payload.StringResult"/>
</core:exports>
</smooks-resource-list>
并在POM中添加依赖项:
<dependency>
<groupId>org.milyn.edi.unedifact</groupId>
<artifactId>d01b-mapping</artifactId>
<version>1.4</version>
</dependency>