Skip to content
API REFERENCEv2

XML to SQL INSERT script API

Prepare SQL INSERT and optional CREATE TABLE text from a record-oriented XML export with the TableConvert conversion API. The source tree is flattened to direct record fields; XML attributes and repeated same-name elements need explicit preprocessing to avoid loss.

REST APIv2 · Direct outputXML → SQL INSERT script1 credits per successful conversion

Try this conversion

Inspect a real sample, preview locally, or send a live request with your own key.

Verified sample
POSThttps://api.tableconvert.com/v2/convert/xml-to-sql

SQL INSERT script response

CREATE TABLE `tableName` (
    `id`	INT,
    `name`	VARCHAR(512),
    `email`	VARCHAR(512)
);

INSERT INTO `tableName` (`id`, `name`, `email`) VALUES ('101', 'Alice', 'alice@example.com');
INSERT INTO `tableName` (`id`, `name`, `email`) VALUES ('102', 'Bob', 'bob@example.com');

Local previews use no credits and process the first imported table or worksheet.

Conversion options
A successful live request uses 1 credits.

Your key is sent only to the conversion API and is never saved by this page.

Things to check before integrating

Before you integrate

Move required attributes into explicit fields and flatten repeated nested groups before sending XML.

Before you integrate

The script is not executed; review inferred types, literal NULL handling and any generated DROP statement before using it.

Code examples

These examples send the sample as multipart/form-data and save the returned bytes unchanged. Set TABLECONVERT_API_KEY in your environment.

XML to SQL INSERT script API · cURL

curl --fail-with-body --max-time 40 \
  'https://api.tableconvert.com/v2/convert/xml-to-sql' \
  --header "Authorization: Bearer $TABLECONVERT_API_KEY" \
  --form-string 'data=<?xml version="1.0" encoding="UTF-8" ?>
<dataset>
  <record><id>101</id><name>Alice</name><email>alice@example.com</email></record>
  <record><id>102</id><name>Bob</name><email>bob@example.com</email></record>
</dataset>' \
  --form-string 'output[create]=true' \
  --form-string 'output[oneInsert]=false' \
  --form-string 'output[drop]=false' \
  --form-string 'output[table]=tableName' \
  --form-string 'output[primaryKey]=' \
  --form-string 'output[dialect]=MySQL' \
  --output 'xml-to-sql.sql'

Requires cURL. Download the sample input first when this example uploads a file.

Authentication

Send Authorization: Bearer YOUR_API_KEY. Let the HTTP client set the multipart boundary; do not set Content-Type manually.

Keep production API keys in server-side environment variables.

Request parameters

The importer treats each direct child of the document root as a record and its child elements as fields. It is a record extractor, not a general XML schema or XSLT transformation.

ParameterTypeDefaultDescription
datastring—Inline XML table content. Choose one of data, file or url.
filebinary—Upload a xml file using multipart/form-data.
urlstring—A supported publicly accessible HTTP or HTTPS file URL.

Send one source: data, file, or url. The examples below use the source mode appropriate for this format.

Output options

Generate SQL INSERT statements and optional table-creation text for a chosen dialect. The API returns a script and does not execute it against a database.

ParameterTypeDefaultDescription
output[create]booleantrueEmit a CREATE TABLE draft before SQL INSERT statements; inspect inferred column types.
output[oneInsert]booleanfalseGroup SQL records into one INSERT with multiple value tuples.
output[drop]booleanfalseEmit DROP TABLE IF EXISTS in the script; review this destructive statement before any separate execution.
output[table]stringtableNameSet the generated table identifier or label; conversion does not create a live database or analytics object.
output[primaryKey]stringEmpty stringAdd a primary-key declaration to the generated SQL CREATE TABLE text.
output[dialect]stringMySQLChoose SQL identifier/literal quoting conventions for the generated script.

Conversion rules

CaseBehavior
Mapping rule 1Root-level child records supply rows, and their child element names supply the union of columns.
Mapping rule 2Headers become quoted identifiers and records become INSERT value tuples in the selected dialect.
Mapping rule 3The source tree is flattened to direct record fields; XML attributes and repeated same-name elements need explicit preprocessing to avoid loss.

How the input is read

  • Use a root element containing repeated record elements with child-element fields.
  • Cell values use element textContent; attributes and deep tree structure are not emitted as separate columns.
  • Repeated field names within one record overwrite earlier values; normalize repeating groups first.
  • Review namespace-prefixed names before generating code identifiers or a new schema.

How the output is written

  • Header names become column identifiers and each record becomes a VALUES tuple.
  • Optional CREATE TABLE types are heuristic; review null handling, identifier quoting and dialect rules.
  • The optional drop setting emits destructive SQL text; review it before any separate database execution.

When to use this API

This conversion in practice

Use a record-oriented XML export as the starting dataset for a reviewed database seed or import script. Move required attributes into explicit fields and flatten repeated nested groups before sending XML.

SQL INSERT script

Prepare a reviewed seed-data or migration-input script from a flat table.

Responses and errors

HTTP statusDescription
200text/plain; charset=utf-8
400Invalid input or conversion parameters.
402Insufficient credits for this request.
403Missing or invalid API key.
413The input exceeds the configured request limit.
415Unsupported input media type.
429Rate limit exceeded.
500The conversion could not be completed.
503The renderer is unavailable or the request timed out.

Check the response before retrying. A new HTTP request is a new conversion and may use credits again.

Limits, billing and versions

Local previews accept up to 200 KB. The current API implementation allows one uploaded file up to 50 MiB, limits each multipart text field to 1 MiB, and gives v2 conversion tasks a 30-second deadline. Deployment limits may be stricter. Read the returned error before retrying; some parser or renderer failures return HTTP 500.

Live calls follow the API credit policy. Failed conversions are refunded; a completed conversion is not undone if the download connection later fails.

View API pricing and credits

Using API v1?

This page documents v2, which returns the output directly. API v1 wraps the result in a JSON envelope. Check the overview before changing an existing integration.

API overview

References and format specifications

Format references explain the underlying syntax. The conversion rules and samples above describe TableConvert’s implementation.