There are many examples of DFDL Schemas and data that can be run using Daffodil. They can be found at:
- DFDLSchemas on github
- DFDL/Daffodil project on forge.mil (for those with access. A CAC Card is required.)
Examples showing how to use the Daffodil API so as to embed Daffodil into an application are at:
Contents
Table of Contents |
---|
Following are commands that can be run from the root directory of the of the daffodil tree. That is, if you download and extract a daffodil release file, from the root directory of that tree.
Note that these commands assume a Linux terminal. If you are using Windows, replace ./bin/daffodil.sh
with .\bin\daffodil.bat
, and use the appropriate file delimiting character when specifying paths.
Visit the Daffodil Command Line Interface
The Daffodil Releases come with an example directory containing DFDL schemas and files used to exercise the Daffodil parser. Following are commands that can be run from the root directory of the of the extracted release. Note that these commands assume a Linux terminal. If you are using Windows, replace ./bin/daffodil.sh
with .\bin\daffodil.bat
, and use the appropriate file delimiting character when specifying paths.
Visit the Daffodil Command Line Interface for more detailed usage on the CLI.
See Daffodil Performance for metrics on how these examples perform.
There is also a separate example integration of Daffodil into the Calabash XProc processor. See the Daffodil Calabash page.
Comma-separated Values (CSV)
This DFDL schema is found at https://github.com/DFDLSchemas/CSV.
We assume you have created a directory named 'examples' in your home directory, and in it you have cloned the CSV git repository via:A comma-separated value file is a file that contains a single row of headers followed by one or more rows of data. The header and data rows are separated into records by a comma. For information on the file format, visit Comma-separated Values.
Code Block | ||||
---|---|---|---|---|
| $ ./bin/daffodil parse --schema examples/csv/csv.dfdl.xsd examples/csv/simpleCSV||||
cd ~/examples
git clone https://github.com/DFDLSchemas/CSV.git |
A comma-separated value file is a file that contains lines that are table rows. There is a single row of headers followed by one or more rows of data. The header and data rows are separated into data fields by a comma. For information on the file format, visit Comma-separated Values.
Code Block | ||||
---|---|---|---|---|
| ||||
$ ./bin/daffodil parse --schema ~/examples/csv/src/main/resources/com/tresys/csv/xsd/csv.dfdl.xsd ~/examples/csv/src/test/resources/com/tresys/csv/data/simpleCSV.csv |
This is the CSV schema:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <!-- Copyright (c) 2012-2015 Tresys Technology, LLC. All rights reserved. Developed by: Tresys Technology, LLC ... --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.tresys.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. 3. Neither the names of Tresys Technology, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. --> <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="xsd/built-in-formats.xsd" /> <xs:annotation> <xs:appinfo source="http://www.ogf.org/dfdl/"> <dfdl:format ref="ex:daffodilTest1" separator="" initiator="" terminator="" leadingSkip='0' textTrimKind="none" initiatedContent="no" alignment="implicit" alignmentUnits="bits" trailingSkip="0" ignoreCase="no" separatorPosition="infix" occursCountKind="parsed" emptyValueDelimiterPolicy="both" representation="text" textNumberRep="standard" lengthKind="delimited" encoding="ASCII" /> </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" dfdl:occursCount="{ fn:count(../../header/title) }" dfdl:occursCountKind="expression" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
last,first,middle,DOB
smith,robert,brandon,1988-03-24
johnson,john,henry,1986-01-23
jones,arya,cat,1986-02-19 |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<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> |
PCAP
The PCAP file format is a binary file format used to capture network packets. For information on this file format, visit the Wireshark Libpcap File Format page.
Code Block | ||||
---|---|---|---|---|
| ||||
$ ./bin/daffodil parse --schema examples/pcap/pcap.dfdl.xsd examples/pcap/icmp.cap |
...
language | xml |
---|---|
title | pcap.dfdl.xsd |
linenumbers | true |
collapse | true |
...
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="xsd/built-in-formats.xsd" />
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format ref="ex:daffodilTest1" separator="" initiator=""
terminator="" leadingSkip='0' textTrimKind="none" initiatedContent="no"
alignment="implicit" alignmentUnits="bits" trailingSkip="0" ignoreCase="no"
separatorPosition="infix" occursCountKind="parsed"
emptyValueDelimiterPolicy="both" representation="text" textNumberRep="standard"
lengthKind="delimited" encoding="ASCII" />
</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"
dfdl:occursCount="{ fn:count(../../header/title) }"
dfdl:occursCountKind="expression" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema> |
And this is the data
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
last,first,middle,DOB
smith,robert,brandon,1988-03-24
johnson,john,henry,1986-01-23
jones,arya,cat,1986-02-19 |
This is the result of using Daffodil to parse that data:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<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> |
PCAP - Packet Capture
This DFDL schema is found at https://github.com/DFDLSchemas/CSV.
The PCAP file format is a binary file format used to capture network packets. For information on this file format, visit the Wireshark Libpcap File Format page.
We assume you have created a directory named 'examples' and in it you have cloned the PCAP git repository via:
Code Block | ||
---|---|---|
| ||
cd ~/examples
git clone https://github.com/DFDLSchemas/PCAP.git |
This is the command line.
Code Block | ||||
---|---|---|---|---|
| ||||
$ ./bin/daffodil parse --schema ~/examples/pcap/src/main/resources/com/tresys/pcap/xsd/pcap.dfdl.xsd ~/examples/pcap/src/test/resources/com/tresys/pcap/data/icmp.cap |
The PCAP Schema is not reproduced here simply due to its size.
The data, viewed as a hex dump, looks like this:
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
0000000 c3d4 a1b2 0002 0004 0000 0000 0000 0000 0000020 ffff 0000 0001 0000 6fc4 51c1 ccf8 000c 0000040 004a 0000 004a 0000 5000 e056 4914 0c00 ... 0001300 0000 5c2f 0002 0024 6261 6463 6665 6867 0001320 6a69 6c6b 6e6d 706f 7271 7473 7675 6177 0001340 6362 6564 6766 6968 |
The resulting infoset, in XML looks like:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<pcap:PCAP xmlns:pcap="urn:pcap:2.4"> <PCAPHeader> <MagicNumber>D4C3B2A1</MagicNumber> <Version> <Major>2</Major> <Minor>4</Minor> </Version> <Zone>0</Zone> <SigFigs>0</SigFigs> <SnapLen>65535</SnapLen> <Network>1</Network> </PCAPHeader> <Packet> <PacketHeader> <Seconds>1371631556</Seconds> <USeconds>838904</USeconds> <InclLen>74</InclLen> <OrigLen>74</OrigLen> </PacketHeader> <pcap:LinkLayer> <pcap:Ethernet> <MACDest>005056E01449</MACDest> <MACSrc>000C29340BDE</MACSrc> <Ethertype>2048</Ethertype> <pcap:NetworkLayer> <pcap:IPv4> <IPv4Header> <Version>4</Version> <IHL>5</IHL> <DSCP>0</DSCP> <ECN>0</ECN> <Length>60</Length> <Identification>55107</Identification> <Flags>0</Flags> <FragmentOffset>0</FragmentOffset> <TTL>128</TTL> <Protocol>1</Protocol> <Checksum>11123</Checksum> <IPSrc>192.168.158.139</IPSrc> <IPDest>174.137.42.77</IPDest> </IPv4Header> <PayloadLength>40</PayloadLength> <Protocol>1</Protocol> <pcap:ICMPv4> <Type>8</Type> <Code>0</Code> <Checksum>10844</Checksum> <Data>02002100</Data> </pcap:ICMPv4> </pcap:IPv4> </pcap:NetworkLayer> </pcap:Ethernet> </pcap:LinkLayer> </Packet> ... </pcap:PCAP> |
...