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:Table dataTable = new ListTable("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.ListTable"> <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-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Table
readData(Reader reader)
Read the data from the XML-file into the data table.static Table
readData(String filename)
Read the data from the XML-file into the data table.static void
writeData(Writer writer, Table dataTable)
Write the data from the data table in XML format.static void
writeData(String filename, Table dataTable)
Write the data from the data table in XML format.
-
-
-
Method Detail
-
writeData
public static void writeData(Writer writer, Table 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
- Table; 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, Table 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
- Table; 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 Table 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 Table 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
-
-