There is a data import tool in OFBiz called the DataFile tool. It uses XML files that describe flat file formats (including character delimited, fixed width, etc) and parses the flat files based on those definitions. So, by design it is somewhat like the Entity Engine. It uses a generic object to represent a row in the flat file. It includes features like a line type code for each line and can support hierarchical flat files (ie where parent/child relationships are implied by sub-records).
The code is in the ofbiz/framework/datafile directory, and there is an XSD there to describe how the data file definition XML file should look.
The DataFile has a web page in WebTools to parse data files and generate entity xml files (that can be imported in OFBiz) from them, and to do in/out testing.
Both the import of fixed width flat files and character delimited files are implemented.
- Definition file: this is an xml file that contains one or more "Data File Definition"s; the grammar of the file is defined in framework/datafile/dtd/datafile.xsd
- Data File Definition: the definition of a data file structure (e.g. names/types of the fields/columns in a "Data File"; the same "Data File" could have more than one "Data File Definition"s (e.g. the definitions could consider different subsets of all the fields available in the data file).
- Data file: the text file that contains all the data (a fixed width or a character delimited text file)
How to use the "Work With Data Files" screen in the Webtools application
Prerequisites: a definition file (containing the fields' definition of the data file) and a data file (containing the data you want to parse/import) should be available in the OFBiz server.
- connect to the Webtools application
- go to the "Work With Data Files" screen
- enter the path to the your definition file in the "Definition Filename or URL" input field
- click on the submit button
- the "Data File Definition Name" input field will be changed into a drop down box containing all the definitions available in the definition file
- select the definition you want to use from the drop down box
- enter the path to the your data file in the "Data Filename or URL" input field
- (optional) click on the submit button; the data file will be parsed and the result will be shown on screen
- if you want to generate an entity xml file that can be later imported in OFBiz, enter a path for it in the "Save to entity xml file:" input field and click on the submit button; the file will be created (see the paragraph "Tips to create Entity Xml Files" for more details)
Tips to create Entity Xml Files
The "Work with Data Files" screen can be used to parse a data file and create an Entity Xml file that can be easily imported in OFBiz (for example using the Webtools-->Entity Import Xml screen). In order to create a good entity xml file you should follow these recommendations when you prepare your "Definition File":
- the record.name attribute must contain the name of the entity in which the records will be imported (for example: <record name="Product" limit="many">)
- the field.name attribute must contain the name of the entity field in which the records will be imported (for example: <field name="productId" type="String"/>)
An example of fixed width flat file import.
Sample fixed width CSV file posreport.csv to be imported:
Sample xml definition file for importing select columns posschema.xml:
In the interface enter something like:
- Definition Filename or URL: posschema.xml
- Data File Definition Name: posreport
- Data Filename or URL: posreport.csv
The types listed in this sample are simple String's but the usual types are available such as Date, Long etc.
Another example reading fixed record little endian binary files
Tab delimited imports
Worth noting that to get tab separated imports working you should use a delimiter of :
Also you may have a look at real life examples in