Document document = new Document(); String[] tableNames = dataSet.getTableNames();   Element rootElem = document.addElement("dataset");   for (int i = 0; i < tableNames.length; i++) { String tableName = tableNames[i]; ITable table = dataSet.getTable(tableName); Column[] columns = table.getTableMetaData().getColumns();   for (int j = 0; j < table.getRowCount(); j++) { Element rowElem = rootElem.addElement(tableName); for (int k = 0; k < columns.length; k++) { Column column = columns[k]; Object value = table.getValue(j, column.getColumnName());   if (value != null && value != ITable.NO_VALUE) { try { String stringValue = DataType.asString(value); rowElem.setAttribute(column.getColumnName(), stringValue); } catch (TypeCastException e) { throw new DataSetException("table=" + tableName + ", row=" + j + ", column=" + column.getColumnName() + ", value=" + value, e); } } } }   if (table.getRowCount() == 0) { rootElem.addElement(tableName); } }
Document document = buildDocument(dataSet);
    public static void write(IDataSet dataSet, OutputStream out)            throws IOException, DataSetException    {        Document document = new Document();        String[] tableNames = dataSet.getTableNames();        // dataset        Element rootElem = document.addElement("dataset");        // tables        for (int i = 0; i < tableNames.length; i++)        {            String tableName = tableNames[i];            ITable table = dataSet.getTable(tableName);            Column[] columns = table.getTableMetaData().getColumns();            // table rows            for (int j = 0; j < table.getRowCount(); j++)            {                Element rowElem = rootElem.addElement(tableName);                for (int k = 0; k < columns.length; k++)                {                    Column column = columns[k];                    Object value = table.getValue(j, column.getColumnName());                    // row values                    if (value != null && value != ITable.NO_VALUE)                    {                        try                        {                            String stringValue = DataType.asString(value);                            rowElem.setAttribute(column.getColumnName(), stringValue);                        }                        catch (TypeCastException e)                        {                            throw new DataSetException("table=" + tableName +                                    ", row=" + j + ", column=" +                                    column.getColumnName() + ", value=" +                                    value, e);                        }                    }                }            }            // empty table            if (table.getRowCount() == 0)            {                rootElem.addElement(tableName);            }        }        // write xml document        document.write(out);    }