📄 xmldataset.java
字号:
/*
*
* The DbUnit Database Testing Framework
* Copyright (C)2002-2004, DbUnit.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package org.dbunit.dataset.xml;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.dbunit.dataset.CachedDataSet;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.IDataSet;
import org.xml.sax.InputSource;
import java.io.*;
/**
* Reads and writes original XML dataset document. This format
* is very verbiose and must conform to the following DTD:
* <pre>
*
* <?xml version="1.0" encoding="UTF-8"?>
* <!ELEMENT dataset (table+)>
* <!ELEMENT table (column*, row*)>
* <!ATTLIST table
* name CDATA #REQUIRED
* >
* <!ELEMENT column (#PCDATA)>
* <!ELEMENT row (value | null | none)*>
* <!ELEMENT value (#PCDATA)>
* <!ELEMENT null EMPTY>
*</pre>
* @author Manuel Laflamme
* @version $Revision: 554 $
* @since Feb 17, 2002
*/
public class XmlDataSet extends CachedDataSet
{
/**
* Logger for this class
*/
private static final Logger logger = LoggerFactory.getLogger(XmlDataSet.class);
private static final String DEFAULT_ENCODING = "UTF8";
/**
* Creates an XmlDataSet with the specified xml reader.
*/
public XmlDataSet(Reader reader) throws DataSetException
{
super(new XmlProducer(new InputSource(reader)));
}
/**
* Creates an XmlDataSet with the specified xml input stream.
*/
public XmlDataSet(InputStream in) throws DataSetException
{
super(new XmlProducer(new InputSource(in)));
}
/**
* Write the specified dataset to the specified output stream as xml.
*/
public static void write(IDataSet dataSet, OutputStream out)
throws IOException, DataSetException
{
logger.debug("write(dataSet=" + dataSet + ", out=" + out + ") - start");
OutputStreamWriter writer = new OutputStreamWriter(out, DEFAULT_ENCODING);
write(dataSet, writer);
}
/**
* Write the specified dataset to the specified writer as xml.
*/
public static void write(IDataSet dataSet, Writer writer)
throws IOException, DataSetException
{
logger.debug("write(dataSet=" + dataSet + ", writer=" + writer + ") - start");
write(dataSet, writer, null);
}
/**
* Write the specified dataset to the specified writer as xml.
*/
public static void write(IDataSet dataSet, Writer writer, String encoding)
throws IOException, DataSetException
{
logger.debug("write(dataSet=" + dataSet + ", writer=" + writer + ", encoding=" + encoding + ") - start");
XmlDataSetWriter datasetWriter = new XmlDataSetWriter(writer, encoding);
datasetWriter.write(dataSet);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -