Howto properly make dbunit reference a dtd file in the xml dataset?

1.3k views Asked by At

How can i setup dbunit to add me the line in the xml dataset tag which references a dtd file?

In my xml file i get my dataset represetned as

<dataset>
    <TABLE COLUMN="value ..."
    ...

But i want to add a reference to the dtd (or about another way)

<!DOCTYPE dataset SYSTEM "../my.dtd">
     <TABLE COLUMN="value" ... 
     ...

The xml is genereated by:

FlatXmlDataSet.write(dataSet, out);

When i add the line by hand, i get a parsing error

java.lang.NullPointerException
at org.dbunit.dataset.xml.FlatXmlProducer.isNewTable(FlatXmlProducer.java:255)
at org.dbunit.dataset.xml.FlatXmlProducer.startElement(FlatXmlProducer.java:429)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:766)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1342)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDriver.scanRootElementHook(XMLDocumentScannerImpl.java:1292)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3122)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:880)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at org.dbunit.dataset.xml.FlatXmlProducer.produce(FlatXmlProducer.java:365)
at org.dbunit.dataset.CachedDataSet.<init>(CachedDataSet.java:97)
at org.dbunit.dataset.xml.FlatXmlDataSet.<init>(FlatXmlDataSet.java:110)
at org.dbunit.dataset.xml.FlatXmlDataSetBuilder.buildInternal(FlatXmlDataSetBuilder.java:264)
at org.dbunit.dataset.xml.FlatXmlDataSetBuilder.build(FlatXmlDataSetBuilder.java:111)
at test.de.planta.server.DBUnitHelper.readDataSet(DBUnitHelper.java:243)
at test.de.planta.server.DBUnitHelper.insertDataFromXMLIntoH2(DBUnitHelper.java:202)
at test.de.planta.server.DBUnitHelper.CleanInsertData(DBUnitHelper.java:95)
at test.de.planta.server.DBUnitHelper.doCleanImport(DBUnitHelper.java:64)
at test.de.planta.server.DBUnitHelper.main(DBUnitHelper.java:57)
1

There are 1 answers

0
Kayaman On

You're missing the actual <dataset> element.

The file should start as follows:

<!DOCTYPE dataset SYSTEM "../my.dtd">
<dataset>
     <TABLE COLUMN="value" ...