Flat XML
FlatXmlDataSet reads and writes flat XML dataset documents. Each XML element corresponds to a table row. Each XML element name corresponds to a table name. The XML attributes correspond to table columns.
Flat XML dataset document sample:
<!DOCTYPE dataset SYSTEM "my-dataset.dtd">
<dataset>
<TEST_TABLE COL0="row 0 col 0" COL1="row 0 col 1" COL2="row 0 col 2"/>
<TEST_TABLE COL1="row 1 col 1"/>
<SECOND_TABLE COL0="row 0 col 0" COL1="row 0 col 1" />
<EMPTY_TABLE/>
</dataset>To specify null values, omit the corresponding attribute. In the above example, the missing COL0 and COL2 attributes of TEST_TABLE’s second row represent null values.
DbUnit matches an attribute to a column without regard to letter case (since 2.7.0, issue 673),
so a row can write col1 for the column that the first row wrote as COL1.
Before 2.7.0, DbUnit read only an attribute spelled exactly like its column, so such a row loaded null for that column.
Table metadata is deduced from the first row of each table. On a later row,
an attribute the first row lacked is ignored — the row is still read, just
without that column, with an "Extra columns on line x" warning — unless you
enable column sensing or supply a DTD. See
Dataset Values: column sensing for the fix.
Beware you may get a NoSuchColumnException if the first row of a table has one or more null values.
Because of that, using a DTD is recommended: DbUnit then takes each table’s metadata from the columns declared in the DTD.
DbUnit supports only an external system URI for the DTD; it can be absolute or relative.
A table that the DTD declares but the file has no element for becomes an empty table of the dataset (since 3.5.0, issue 496),
so DELETE_ALL and CLEAN_INSERT clear it; earlier versions leave such a table out of the dataset.
ReplacementDataSet’s [NULL placeholder] is another
way to cope with a first-row null.
For binary/BLOB data, literal and relative dates, UUID literals, booleans and numbers from strings, and empty-string handling, see Dataset Values — those rules are the same for every format.
Build one with FlatXmlDataSetBuilder:
IDataSet dataSet = new FlatXmlDataSetBuilder().build(new File("dataset.xml"));

