SQL to XML Converter
CV-68Paste INSERT statements and get XML with one element per row and one child element per column. Choose how NULL is written.
Runs in your browser. Nothing is uploaded.
SQL INSERT statements
XML
How to use it
- Paste your INSERT ... VALUES statements into the input box.
- Choose how NULL is written, and whether rows are named after the table or just row.
- Turn the XML declaration and backslash escapes on or off, and pick the indent.
- Copy the XML or download it as a .xml file.
The XML structure
The output has a data root. Each row becomes an element named after the table, or row if you choose that, and each column becomes a child element. Rows from several INSERT statements follow each other under the same root. Every value is text with no types. Numbers are copied exactly as written, so large integers are not rounded, and expressions such as NOW() are written as their source text and not evaluated.
NULL, names and escaping
NULL can be an empty element, an element with xsi:nil="true" (the xsi namespace is declared on the root), or no element at all. An empty element cannot tell NULL from an empty string, so use xsi:nil if the difference matters. Table and column names that are not valid XML names have invalid characters replaced with an underscore, and repeated names get _2, _3. Text is escaped, and control characters that XML 1.0 cannot hold are reported as an error.
What is read
Only INSERT ... VALUES statements are read. Other statements and comments are skipped, and INSERT ... SELECT is rejected with a message. Strings lose their quotes, and a doubled quote becomes one. Backslash escapes are decoded only if you turn that option on, which you want for MySQL dumps. Names can be plain, [bracketed], `backticked` or "double-quoted".
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
No INSERT INTO ... VALUES statements found. Paste statements such as INSERT INTO users (id, name) VALUES (1, 'Ada'); | The input has no INSERT ... VALUES statement. | Paste at least one INSERT statement with a VALUES list. |
Row 2 of the INSERT into t has 1 value but the column list has 2 | A row has a different number of values than the column list. | Add or remove a value so every row matches the columns. |
Questions people ask
How do I convert SQL INSERT statements to XML?
Paste the statements and the XML appears. Each row becomes an element and each column a child element. Copy it or download it as a .xml file.
How are NULL values written?
Choose Empty element, xsi:nil="true" or leave the element out. Use xsi:nil if a reader of the XML must be able to tell NULL from an empty string.
Can I name the row element myself?
You can choose between the table name and the word row. For another name, change it with a find and replace afterwards. Everything runs in the page, so you can test with real data.
Does it work with several tables?
Yes. Each INSERT uses its own table name for its rows, and all rows go under one data root in the order they appear. If the output is not what you expect, check the input first.
Are numbers converted?
No. Numbers are copied exactly as written, as text, so nothing is rounded and 19.90 stays 19.90. The result updates as soon as you change the input or an option.
About this tool
Reads INSERT INTO table (columns) VALUES (...), (...); statements. The output has a <data> root, one element per row named after the table (or row, as you choose), and one child element per column. Other statements and comments are skipped. Rows from several statements go one after another in the same root. Strings lose their quotes and doubled quotes become one; numbers are copied exactly as written, so large integers are not rounded; expressions such as NOW() are written as their source text and are not evaluated. Every value is text with no types. NULL can be an empty element, an element with xsi:nil="true" (the xsi namespace is declared on the root), or no element, and an empty element cannot tell NULL from an empty string. Table and column names that are not valid XML names have invalid characters replaced with _, and repeated names get _2, _3. Text is escaped, and control characters XML 1.0 cannot hold are an error. Backslash escapes are read only if you turn that option on.