DFDL
Since Camel 4.11
The DFDL Data Format allows you to transform the fixed format data such as EDI message from/to XML using Data Format Description Language, also known as DFDL. DFDL schema is an XML schema annotated with DFDL elements and attributes.
While DFDL schema defines the XML representation of the data structure, it also defines how the conversion between the fixed format and XML is processed using DFDL annotations.
This component uses Apache Daffodil as an underlying DFDL implementation.
Maven users will need to add the following dependency to their pom.xml for this data format:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-dfdl</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> Usage
Unmarshal (Fixed format to XML)
Below is an example of using the DFDL Data Format to unmarshal an EDI message into an XML DOM Document:
-
Java
-
YAML
from("direct:unmarshal")
.unmarshal().dfdl("X12-837P.dfdl.xsd")
.log("Unmarshalled X12 837P message: ${body}"); - route:
from:
uri: direct:unmarshal
steps:
- unmarshal:
dfdl:
schemaUri: X12-837P.dfdl.xsd
- log:
message: "Unmarshalled X12 837P message: ${body}" Marshal (XML to fixed format)
Below is an example of using the DFDL Data Format to marshal XML (a DOM Document, or XML text) into an EDI message:
-
Java
-
YAML
from("direct:marshal")
.marshal().dfdl("X12-837P.dfdl.xsd")
.log("Marshalled X12 837P message: ${body}"); - route:
from:
uri: direct:marshal
steps:
- marshal:
dfdl:
schemaUri: X12-837P.dfdl.xsd
- log:
message: "Marshalled X12 837P message: ${body}" DFDL Data Format Options
The DFDL dataformat supports the following options which are listed below.
| Name | Default | Java Type | Description |
|---|---|---|---|
| Required The path to the DFDL schema file. | ||
| The root element name of the schema to use. If not specified, the first root element in the schema will be used. | ||
| The root namespace of the schema to use. |
Message Body
The message body at each side of the DFDL data format: Marshal input and Unmarshal input are the bodies marshal and unmarshal can take, and Marshal output and Unmarshal output the body after them.
| Side | Body | Description |
|---|---|---|
Marshal input |
| The XML infoset of the DFDL schema, as text or as a DOM Document (or another DOM Node or Source), which is converted to a DOM Document. |
Marshal output |
| The data in the format the DFDL schema describes, in the stream cache, or a byte array when stream caching is off. |
Unmarshal input |
| Data in the format the DFDL schema describes, such as an EDI message. |
Unmarshal output |
| The XML infoset as a DOM Document. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers are described in the Camel Catalog.