0

我正在使用 Smooks 1.5 并尝试从 EDI 消息生成 XML 文件,我也尝试使用标准插件,它生成大量命名空间,我无法处理 FreeMaker 模板引擎的原因。这个例子没有 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'
...

我的问题是,我必须如何设置映射文件?我需要指定每一行还是只指定我感兴趣的字段就足够了?

我的映射文件:

-->
<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 配置如下所示:

<?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 消息中找不到任何字段吗?

雷托

4

1 回答 1

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>  
于 2015-03-03T15:21:09.077 回答