Package org.djutils.data.xml
Class XMLData
- java.lang.Object
-
- org.djutils.data.xml.XMLData
-
public final class XMLData extends Object
XMLData takes care of reading and writing of table data in XML format. The reader and writer use a streaming API to avoid excessive memory use. The class can be used, e.g., as follows:DataTable dataTable = new ListDataTable("data", "dataTable", columns); Writer writer = new FileWriter("c:/data/data.xml"); XMLData.writeData(writer, dataTable);
The XML document has the following structure:<xmldata> <table id="tableId" description="description" class="org.djutils.data.ListDataTable"> <column nr="0" id="obsNr" description="observation nr" type="int"></column> <column nr="1" id="value" description="observation value" type="double"></column> <column nr="2" id="comment" description="comment" type="java.lang.String"></column> </table> <data> <record index="0"> <value nr="0" content="2"></value> <value nr="1" content="18.6"></value> <value nr="2" content="normal"></value> </record> <record index="1"> <value nr="0" content="4"></value> <value nr="1" content="36.18"></value> <value nr="2" content="normal"></value> </record> </data> </xmldata>
Copyright (c) 2020-2021 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DataTable
readData(Reader reader)
Read the data from the XML-file into the data table.static DataTable
readData(String filename)
Read the data from the XML-file into the data table.static void
writeData(Writer writer, DataTable dataTable)
Write the data from the data table in XML format.static void
writeData(String filename, DataTable dataTable)
Write the data from the data table in XML format.
-
-
-
Method Detail
-
writeData
public static void writeData(Writer writer, DataTable dataTable) throws IOException, TextSerializationException, XMLStreamException
Write the data from the data table in XML format.- Parameters:
writer
- Writer; the writer that writes the data, e.g. to a filedataTable
- DataTable; the data table to write- Throws:
IOException
- on I/O error when writing the dataTextSerializationException
- on unknown data type for serializationXMLStreamException
- on XML write error
-
writeData
public static void writeData(String filename, DataTable dataTable) throws IOException, TextSerializationException, XMLStreamException
Write the data from the data table in XML format.- Parameters:
filename
- String; the file name to write the data todataTable
- DataTable; the data table to write- Throws:
IOException
- on I/O error when writing the dataTextSerializationException
- on unknown data type for serializationXMLStreamException
- on XML write error
-
readData
public static DataTable readData(Reader reader) throws IOException, TextSerializationException, XMLStreamException
Read the data from the XML-file into the data table. Use the metadata to reconstruct the data table.- Parameters:
reader
- Reader; the reader that can read the data, e.g. from a file- Returns:
- dataTable the data table reconstructed from the meta data and filled with the data
- Throws:
IOException
- on I/O error when reading the dataTextSerializationException
- on unknown data type for serializationXMLStreamException
- on XML read error
-
readData
public static DataTable readData(String filename) throws IOException, TextSerializationException, XMLStreamException
Read the data from the XML-file into the data table. Use the metadata to reconstruct the data table.- Parameters:
filename
- String; the file name to read the data from- Returns:
- dataTable the data table reconstructed from the meta data and filled with the data
- Throws:
IOException
- on I/O error when reading the dataTextSerializationException
- on unknown data type for serializationXMLStreamException
- on XML read error
-
-