Search code examples
xmljava-ee-6smooks

Multiple mapping model for smooks edi to xml


When i add just one mappingmodel then it works perfect but actually i want to add multiple mapping model as i have added onto the following code. Can someone please assist how can i do that.

Smooks-config.xml

<?xml version="1.0"?>
<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">

    <edi:reader mappingModel="/example/edi-to-xml-author-full-mapping.xml" />
    <edi:reader mappingModel="/example/edi-to-xml-author-full-map.xml" /

</smooks-resource-list>

Test.java

  protected static String runSmooksTransform() throws IOException, SAXException, SmooksException {
        Locale.setDefault(new Locale("en", "IE"));


    Smooks smooks = new Smooks("smooks-config.xml");
    try {

        ExecutionContext executionContext = smooks.createExecutionContext();

        StringResult result = new StringResult();
        smooks.filterSource(executionContext, new StreamSource(new ByteArrayInputStream(messageIn)), result);

        return result.getResult();
    } finally {
        smooks.close();
    }
}

Solution

  • I'm afraid that's not going to work. There can only be one top level EDI reader in the smooks config.

    If you want to modularise the config then you can do that and use imports in the EDI mapping model itself.

    If you want need to process different EDI messages then you need to use different smooks instances with different EDI reader mapping model configs. The UNEDIFACT reader does support different EDI messages as part of an "exchange", but that's a different reader and is specific to the UNEDIFACT protocol.