SQL to XML

Convert a dump of INSERT statements into XML rows for an import job or a legacy interface.

SQL inserts
XML
Runs locally in your browser

About the SQL to XML

Plenty of enterprise interfaces still speak XML, and the data you have is often a SQL dump. This converter extracts the column names and value tuples from INSERT statements and writes an XML document: one row element per tuple, wrapped in a root element, with names you choose for both.

Two layouts are available because receiving systems disagree about which is correct. The element layout writes one child element per column, which reads well and copes with long text. The attribute layout puts every column on the row element itself, which is far more compact and is what many older import formats expect. Column names that are not valid XML names have their punctuation replaced and a leading digit prefixed, so the document always parses.

NULL needs a decision rather than a default. An empty element keeps the column visible with no content, leaving it out signals absence, and the xsi:nil attribute is the schema aware form that a validating parser understands. Pick whichever the consumer documents, because the three are not interchangeable.

Values are XML escaped, so an ampersand in a company name or a less than sign in a note cannot break the document. Several INSERT statements against different tables are nested under one element per table. Check the output with the XML Validator, or go the other way with XML to JSON.

How to use

  1. Paste the INSERT statements, or press Sample to load weather readings.
  2. Name the root and row elements to match the format your consumer expects.
  3. Tick Columns as attributes for the compact layout.
  4. Choose how NULL columns should appear, then download rows.xml.

Common questions

Elements or attributes, which should I choose?
Follow the schema you are feeding. Elements handle long or structured text better, attributes make a much smaller file.
How is NULL represented?
Three ways: an empty element, no element at all, or the xsi:nil attribute. Pick the one your consumer documents.
What if a column name is not a valid XML name?
Punctuation is replaced with underscores and a leading digit gets an underscore prefix, so the document always parses.
Do I get one file for several tables?
Yes. Each table becomes its own element under the root, holding that table rows.