Smooks EDI writer

最后都变了- 提交于 2019-12-05 16:13:39

I managed to do this using the same schema used in the unedifact:reader

Smooks-config:

<?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">
    <import file="/org/milyn/edi/unedifact/d96a/message-bindingconfig.xml" />
    <import file="/org/milyn/smooks/edi/unedifact/model/r41/bindings/unedifact-interchange.xml" />
    <core:exports>
        <core:result type="org.milyn.payload.JavaResult"/>
    </core:exports>
</smooks-resource-list>

The result is a HashMap withe the elements readed. Now that i have objets i can make any modifications and after that i use the document interchange factory: ex D96AInterchangeFactory

D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
UNEdifactInterchange41 unEdifactInterchange = (UNEdifactInterchange41) map.get("unEdifactInterchange");
StringWriter ediOutStream = new StringWriter();
factory.toUNEdifact(unEdifactInterchange, ediOutStream);

Finally i can use toString() to get my document:

System.out.println("document: " + ediOutStream.toString());

According to the Smooks website:

Smooks can read and write data formats other than XML, including EDI, CSV, JSON, YAML, Java. To read non-XML data, you typically need to configure a for that data type. Writing data typically involves configuring a template that operates on the event stream produced by the (as in the case of XSLT), or on the beans in the BeanContext (as in the case of FreeMarker). You can also simply allow Smooks to serialize the event stream produced by the input reader, which will produce XML, giving an effective NNN to XML transformation by simply configuring a reader for the input source.

So, yes, there is a possibility to generate EDI with Smooks.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!