The DFDL cartridge opens up Smooks to an incredible number of data formats (e.g., SWIFT, ISO8583, HL7). In fact, this cartridge forms the foundations of the EDI and EDIFACT cartridges. The DFDL cartridge deserializes (i.e., parses) non-XML data and serializes (i.e., unparses) XML according to the structure described in a DFDL schema. Take the subsequent DFDL schema as an example:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/" xmlns:ex="http://example.com"
targetNamespace="http://example.com" elementFormDefault="unqualified">
<xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format ref="ex:GeneralFormatPortable" separator="" initiator=""
terminator="" textTrimKind="none" initiatedContent="no" ignoreCase="no"
separatorPosition="infix" occursCountKind="implicit"
emptyValueDelimiterPolicy="both" representation="text" textNumberRep="standard"
lengthKind="delimited" encoding="ASCII" encodingErrorPolicy="error" />
</xs:appinfo>
</xs:annotation>
<xs:element name="file">
<xs:complexType>
<xs:sequence dfdl:separator="%NL;" dfdl:separatorPosition="postfix">
<xs:element name="header" minOccurs="0" maxOccurs="1"
dfdl:occursCountKind="implicit">
<xs:complexType>
<xs:sequence dfdl:separator=",">
<xs:element name="title" type="xs:string" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="record" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence dfdl:separator=",">
<xs:element name="item" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
This schema describes the structure of CSV data like the one below:
last,first,middle,DOB
smith,robert,brandon,1988-03-24
johnson,john,henry,1986-01-23
jones,arya,cat,1986-02-19
A Smooks config parsing the above CSV using the DFDL cartridge would be written as:
<?xml version="1.0"?>
<smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
xmlns:dfdl="https://www.smooks.org/xsd/smooks/dfdl-1.0.xsd">
<dfdl:parser schemaURI="/csv.dfdl.xsd"/>
...
</smooks-resource-list>
dfdl:parser
is a reader and its schemaURI
attribute references the DFDL schema driving the parsing behaviour. Assuming input.csv is the source, dfdl:parser
will generate the event stream:
<ex:file xmlns:ex="http://example.com">
<header>
<title>last</title>
<title>first</title>
<title>middle</title>
<title>DOB</title>
</header>
<record>
<item>smith</item>
<item>robert</item>
<item>brandon</item>
<item>1988-03-24</item>
</record>
<record>
<item>johnson</item>
<item>john</item>
<item>henry</item>
<item>1986-01-23</item>
</record>
<record>
<item>jones</item>
<item>arya</item>
<item>cat</item>
<item>1986-02-19</item>
</record>
</ex:file>
Shown in the next snippet is a pipeline enclosing the dfdl:unparser
visitor:
<?xml version="1.0"?>
<smooks-resource-list xmlns="https://www.smooks.org/xsd/smooks-2.0.xsd"
xmlns:core="https://www.smooks.org/xsd/smooks/smooks-core-1.6.xsd"
xmlns:dfdl="https://www.smooks.org/xsd/smooks/dfdl-1.0.xsd">
...
<core:smooks filterSourceOn="#document">
<core:action>
<core:inline>
<core:replace/>
</core:inline>
</core:action>
<core:config>
<smooks-resource-list>
<dfdl:unparser schemaURI="/csv.dfdl.xsd" unparseOnNode="*"/>
</smooks-resource-list>
</core:config>
</core:smooks>
</smooks-resource-list>
In contrast to the dfdl:parser
schemaURI
attribute , the schemaURI
schema in dfdl:unparser
drives the unparsing behaviour. dfdl:unparser
replaces each node in the event stream with its serialized CSV counterpart, essentially implementing a passthrough application.
The DFDL cartridge supports variables, on disk caching, and trace debugging. Consult the XSD documentation for further information.
<dependency>
<groupId>org.smooks.cartridges</groupId>
<artifactId>smooks-dfdl-cartridge</artifactId>
<version>1.0.0-RC1-SNAPSHOT</version>
</dependency>
Smooks DFDL Cartridge is open source and licensed under the terms of the Apache License Version 2.0, or the GNU Lesser General Public License version 3.0 or later. You may use Smooks DFDL Cartridge according to either of these licenses as is most appropriate for your project.
SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-or-later