Skip to main content

Flexi2XML Converter

Flexi2XML Conversion Tool for Converting XML Formats

Written by Petr Pech

Flexi2XML can be used as a conversion tool for transferring data from and to ABRA Flexi. It can open a file, convert it to XML, apply a conversion script to it, and write out the result, in both directions. To find out how to get the tool, see the article Downloading Flexi2XML.


Advanced conversion from XLS to Flexi

ABRA Flexi has basic built-in options for importing from XLS (Excel). For more complex cases, such as when column names don't match the properties of the record type, or when values need to be recalculated or assembled from multiple files, you need to use the Flexi2XML tool.


Converting from Excel

The tool reads both XLS and XLSX files. Let's take a workbook like this:

Price list

Customer

Price

8593026341407

FLEXI

1000.0

8593026341407

ARIT

900.0

8593026341407

VFH

1050.0

8593026341407

ABRA

1100.0


Converting from XLS to XML

To enable further processing, we first convert the workbook to XML:

flexibee2xml --from-xls soubor.xls --evidence odberatel --to-xml soubor.xml

The result is XML in which the column names become element names:

<?xml version="1.0" encoding="utf-8"?>
<winstrom version="1.0">
<odberatel>
<Ceník>8593026341407</Ceník>
<Odběratel>FLEXI</Odběratel>
<Cena>1000.0</Cena>
</odberatel>
<odberatel>
<Ceník>8593026341407</Ceník>
<Odběratel>ARIT</Odběratel>
<Cena>900.0</Cena>
</odberatel>
</winstrom>

ℹ️ The --evidence parameter only specifies the name of the row element. If you omit it, each row is wrapped in a generic <row>.

⚠️ On Linux and macOS, enclose the semicolon in quotation marks — --delimeter ";". Without them, the shell treats it as a command separator and discards part of the command. (The switch really is named --delimeter, typo included.)

If the column names directly matched the property names in Flexi XML, we'd be done. That is exactly how CSV and XLS handling works in the REST API. Usually, though, the XML still needs to be adjusted, and that's what XSL transformations are for.


Converting from XML to XML (XSLT)

XSL transformations are a standardized tool, but individual implementations tend to differ. That is why Flexi2XML is built on the same core as ABRA Flexi, which guarantees maximum compatibility.

Let's prepare the conversion script odberatel-in.xslt:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xalan/java" version="1.0" exclude-result-prefixes="java">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<xsl:template match="/winstrom">
<winstrom version="1.0">
<xsl:apply-templates select="odberatel"/>
</winstrom>
</xsl:template>
<xsl:template match="odberatel">
<odberatel>
<firma>code:<xsl:value-of select="java:flexibee.Tool.toUpper(Odběratel)"/></firma>
<cenik>code:<xsl:value-of select="java:flexibee.Tool.toUpper(Ceník)"/></cenik>
<prodejCena>
<xsl:value-of select="Cena"/>
</prodejCena>
</odberatel>
</xsl:template>
</xsl:stylesheet>

There are many introductions to XSLT, for example The Complete Guide to XSLT or Jirka Kosek's introduction. In XSLT you can iterate (<xsl:for-each/>), apply conditions (<xsl:if/>), and index content (<xsl:key/>); however, it is not classic iterative programming.

We then run the transformation:

flexibee2xml --from-xml soubor.xml --run-xslt odberatel-in.xslt --to-xml vysledek.xml

Or with a single command that skips the intermediate step:

flexibee2xml --from-xls soubor.xls --evidence odberatel --run-xslt odberatel-in.xslt --to-xml vysledek.xml

The result can then be imported into ABRA Flexi either directly or by using batch processing.


Switch overview

The tool itself prints the full list when you use the --help parameter. Input and output formats can be combined freely, so the tool can also convert between two spreadsheet formats without modifying the data.

Switch

Meaning

--from-xml, --from-json, --from-csv, --from-xls, --from-xlsx, --from-dbf

Input file and its format.

--to-xml, --to-csv, --to-xls, --to-xlsx, --to-dbf

Output file and its format.

--evidence

Name of the row element in the resulting XML; if omitted, row is used.

--run-xslt

Applies an XSL transformation to the data.

--params

Optional parameters for XSLT or for batch uploading.

--delimeter, --encoding, --no-header

Delimiter, encoding, and suppression of the header row for CSV.

--memo

Name of the MEMO file for the DBF format.

--deduplicate

Removes duplicate records.

--split

Splits a large XML file into smaller files.

--load, --file, --id

Batch uploading based on a configuration file. See Batch processing.

--help

Prints the tool version and an overview of the switches.

💡 Unlike the REST API, which silently ignores unknown parameters, the tool reports a typo in a switch name as Unrecognized option and exits. This way, the error is caught immediately.


A few closing notes

  • The resulting XSLT transformation can be saved as a custom transformation directly in your company, and then used from the REST API as well, with the format parameter. If you want it built directly into Flexi, contact our support.

  • You can also process multiple files at once. This is useful when you have one CSV or XLS file with invoice headers and another with line items.

  • Flexi2XML can also be used to split a large XML file into many small ones and then upload them one after another.


Related

Did this answer your question?