Package org.dbunit.dataset.xml
Class FlatXmlDataSet
java.lang.Object
org.dbunit.dataset.AbstractDataSet
org.dbunit.dataset.CachedDataSet
org.dbunit.dataset.xml.FlatXmlDataSet
- All Implemented Interfaces:
IDataSet,IDataSetConsumer
Reads and writes flat XML dataset document. 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 corresponding attribute. In the above example, missing COL0 and COL2 attributes of TEST_TABLE second row represents null values.
Table metadata is deduced from the first row of each table by default. Beware that DbUnit may think a table misses some columns if the first row of that table has one or more null values. You can do one of the following things to avoid this:
- Use a DTD. DbUnit will use the columns declared in the DTD as table metadata. DbUnit only supports external system URI. The URI can be absolute or relative.
- Since DBUnit 2.3.0 there is a functionality called "column sensing" which basically
reads in the whole XML into a buffer and dynamically adds new columns as they appear.
It can be used as demonstrated in the following example:
// since dbunit 2.4.7 FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder(); builder.setInputSource(new File("src/xml/flatXmlTableTest.xml")); builder.setColumnSensing(true); IDataSet dataSet = builder.build(); // or dbunit release invalid input: '<'= 2.4.6: boolean enableColumnSensing = true; IDataSet dataSet = new FlatXmlDataSet( new File("src/xml/flatXmlTableTest.xml"), false, enableColumnSensing);
- Since:
- 1.0 (Mar 12, 2002)
- Version:
- $Revision$ $Date$
- Author:
- Manuel Laflamme, gommma (gommma AT users.sourceforge.net), Last changed by: $Author$
-
Field Summary
Fields inherited from class org.dbunit.dataset.AbstractDataSet
_orderedTableNameMap -
Constructor Summary
ConstructorsConstructorDescriptionFlatXmlDataSet(File xmlFile) Deprecated.FlatXmlDataSet(File xmlFile, boolean dtdMetadata) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(File xmlFile, boolean dtdMetadata, boolean columnSensing) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(File xmlFile, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(InputStream xmlStream) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(InputStream xmlStream, boolean dtdMetadata) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(InputStream xmlStream, InputStream dtdStream) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(InputStream xmlStream, IDataSet metaDataSet) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(Reader xmlReader) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(Reader xmlReader, boolean dtdMetadata) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(Reader xmlReader, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(Reader xmlReader, Reader dtdReader) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(Reader xmlReader, IDataSet metaDataSet) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(URL xmlUrl) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(URL xmlUrl, boolean dtdMetadata) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(URL xmlUrl, boolean dtdMetadata, boolean columnSensing) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(URL xmlUrl, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetFlatXmlDataSet(FlatXmlProducer flatXmlProducer) Creates a newFlatXmlDataSetwith the data of the given producer.FlatXmlDataSet(InputSource source) Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSet -
Method Summary
Modifier and TypeMethodDescriptionstatic voidwrite(IDataSet dataSet, OutputStream out) Write the specified dataset to the specified output stream as xml.static voidWrite the specified dataset to the specified writer as xml.static voidWrite the specified dataset to the specified writer as xml.static voidwriteDtd(IDataSet dataSet, OutputStream out) Methods inherited from class org.dbunit.dataset.CachedDataSet
createIterator, endDataSet, endTable, row, startDataSet, startTableMethods inherited from class org.dbunit.dataset.AbstractDataSet
createTableNameMap, getTable, getTableMetaData, getTableNames, getTables, initialize, isCaseSensitiveTableNames, iterator, reverseIterator, toString
-
Constructor Details
-
FlatXmlDataSet
Creates a newFlatXmlDataSetwith the data of the given producer.- Parameters:
flatXmlProducer- The producer that provides theFlatXmlDataSetcontent- Throws:
DataSetException- Since:
- 2.4.7
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified InputSource.- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml file. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlFile- the xml file- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml file. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlFile- the xml filedtdMetadata- iffalsedo not use DTD as metadata- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(File xmlFile, boolean dtdMetadata, boolean columnSensing) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml file. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlFile- the xml filedtdMetadata- iffalsedo not use DTD as metadatacolumnSensing- Whether or not the columns should be sensed automatically. Every XML row is scanned for columns that have not been there in a previous column.- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(File xmlFile, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml file. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlFile- the xml filedtdMetadata- iffalsedo not use DTD as metadatacolumnSensing- Whether or not the columns should be sensed automatically. Every XML row is scanned for columns that have not been there in a previous column.caseSensitiveTableNames- Whether or not this dataset should use case sensitive table names- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml URL. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlUrl- the xml URL- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml URL. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlUrl- the xml URLdtdMetadata- iffalsedo not use DTD as metadata- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(URL xmlUrl, boolean dtdMetadata, boolean columnSensing) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml URL. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlUrl- the xml URLdtdMetadata- iffalsedo not use DTD as metadatacolumnSensing- Whether or not the columns should be sensed automatically. Every XML row is scanned for columns that have not been there in a previous column.- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(URL xmlUrl, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml file. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlUrl- the xml filedtdMetadata- iffalsedo not use DTD as metadatacolumnSensing- Whether or not the columns should be sensed automatically. Every XML row is scanned for columns that have not been there in a previous column.caseSensitiveTableNames- Whether or not this dataset should use case sensitive table names- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml reader. Relative DOCTYPE uri are resolved from the current working directory.- Parameters:
xmlReader- the xml reader- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml reader. Relative DOCTYPE uri are resolved from the current working directory.- Parameters:
xmlReader- the xml readerdtdMetadata- iffalsedo not use DTD as metadata- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(Reader xmlReader, boolean dtdMetadata, boolean columnSensing, boolean caseSensitiveTableNames) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml file. Relative DOCTYPE uri are resolved from the xml file path.- Parameters:
xmlReader- the xml readerdtdMetadata- iffalsedo not use DTD as metadatacolumnSensing- Whether or not the columns should be sensed automatically. Every XML row is scanned for columns that have not been there in a previous column.caseSensitiveTableNames- Whether or not this dataset should use case sensitive table names- Throws:
IOExceptionDataSetException- Since:
- 2.4.3
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml and dtd readers.- Parameters:
xmlReader- the xml readerdtdReader- the dtd reader- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml reader.- Parameters:
xmlReader- the xml readermetaDataSet- the dataset used as metadata source.- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml input stream. Relative DOCTYPE uri are resolved from the current working directory.- Parameters:
xmlStream- the xml input stream- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(InputStream xmlStream, boolean dtdMetadata) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml input stream. Relative DOCTYPE uri are resolved from the current working directory.- Parameters:
xmlStream- the xml input streamdtdMetadata- iffalsedo not use DTD as metadata- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(InputStream xmlStream, InputStream dtdStream) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml and dtd input stream.- Parameters:
xmlStream- the xml input streamdtdStream- the dtd input stream- Throws:
IOExceptionDataSetException
-
FlatXmlDataSet
public FlatXmlDataSet(InputStream xmlStream, IDataSet metaDataSet) throws IOException, DataSetException Deprecated.since 2.4.7 - useFlatXmlDataSetBuilderto create aFlatXmlDataSetCreates an FlatXmlDataSet object with the specified xml input stream.- Parameters:
xmlStream- the xml input streammetaDataSet- the dataset used as metadata source.- Throws:
IOExceptionDataSetException
-
-
Method Details
-
write
Write the specified dataset to the specified output stream as xml.- Throws:
IOExceptionDataSetException
-
write
Write the specified dataset to the specified writer as xml.- Throws:
IOExceptionDataSetException
-
write
public static void write(IDataSet dataSet, Writer writer, Charset charset) throws IOException, DataSetException Write the specified dataset to the specified writer as xml.- Throws:
IOExceptionDataSetException
-
writeDtd
public static void writeDtd(IDataSet dataSet, OutputStream out) throws IOException, DataSetException Write a DTD for the specified dataset to the specified output.- Throws:
IOExceptionDataSetException
-
FlatXmlDataSetBuilderto create aFlatXmlDataSet