XML to SQL

Convert XML to SQL instantly in your browser.

Local Your input is processed locally in your browser. Found a problem? Report an issue

What XML to SQL does

XML to SQL reads XML and writes it as SQL. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.

XML is a markup format for structured data, made of nested elements and attributes. Feeds, office files and many older APIs use it. SQL INSERT statements add rows to a database table. Running them in MySQL, PostgreSQL, SQLite or SQL Server loads the data.

XML to SQL example

Input

<users><user id="1"><name>Ada</name></user><user id="2"><name>Lin</name></user></users>

Output

-- Table name: data. Rename it to match your database.
INSERT INTO data ("@id", "name") VALUES (1, 'Ada');
INSERT INTO data ("@id", "name") VALUES (2, 'Lin');

The output is what this tool produces for the input above it.

How it works

Reading XML. The XML is parsed and the repeated elements under the root become the rows, with attributes as columns that start with @.

Writing SQL. Each record becomes one INSERT INTO data (...) VALUES (...); statement. Column names are the keys of the records, with nested objects flattened into dotted names and quoted as identifiers. Text is put in single quotes with any single quote doubled, numbers are written as numbers, true and false become TRUE and FALSE, and missing values become NULL.

Details and limits

  • Everything runs on your device, so there is no upload and no fixed size limit; very large inputs depend on its memory.
  • It works in current browsers on phones, tablets and computers, and it is free with no account.
  • The table is named data. Change the name, and add a CREATE TABLE statement if the table does not exist yet.
  • Numbers are detected only when the whole value is a plain number such as 42 or 3.5.

Questions

Is my data uploaded?

No. The conversion runs in your browser.

Is XML to SQL free?

Yes, with no sign-up and no limit on use.

Which databases accept the output?

MySQL, MariaDB, PostgreSQL, SQLite and SQL Server all accept these INSERT statements. Column names are in double quotes, the SQL standard; in MySQL, turn on ANSI_QUOTES or replace them with backticks.

Can I convert SQL back to XML?

Not with this tool. To get rows out of a database, export the query result as CSV or JSON from your database client.