ConvertCSV

Browser-based CSV converter

CSV to XML Converter

Convert CSV rows into structured XML records. Paste CSV, upload a file, preview the output, then copy or download the converted result.

Input

Paste CSV or upload a CSV file

Output Preview

XML

Convert your input to preview the output here.

CSV to XML Converter

XML is still required by many enterprise systems, EDI workflows, government portals, and legacy integrations that will not accept a plain CSV upload. This free CSV to XML converter turns spreadsheet rows into well-formed XML: each row becomes a record element, each column becomes a child element, and special characters are escaped so the document stays valid.

Paste CSV or upload a .csv file, optionally set your own root and record element names, then copy or download the result. Conversion runs entirely in your browser — your spreadsheet content is not uploaded to a server as part of the transform.

The sections below cover how headers become element names, how escaping and sanitization work, when you still need namespaces or XSD tweaks afterward, Excel/CSV preprocessing tips, and a full troubleshooting and FAQ guide for real import targets.

Key features

  • Lets you set a custom root element and record element name instead of a fixed records/record template.
  • Escapes XML special characters (&, <, >, ", ') automatically so the output is always well-formed.
  • Sanitizes CSV column headers into valid child element names, fixing spaces and leading digits.
  • Adds a standard XML declaration header (<?xml version="1.0" encoding="UTF-8"?>) automatically.
  • Produces indented, human-readable XML rather than a single unbroken line.
  • Runs client-side in the browser so CSV content is not sent to a server for conversion.
  • Handles quoted CSV fields so commas and newlines inside cells stay inside the matching XML text node.

About the CSV to XML format

CSV is a flat table: one header row and one data row per record. XML expects a tree: a root node, repeating record nodes, and named children for each field. This converter builds that tree by wrapping the dataset in a root element (default records), wrapping each row in a record element (default record), and mapping every column header to a child element whose text content is the cell value.

Headers that are not valid XML names are sanitized automatically: spaces become underscores, and a leading underscore is added if a header starts with a digit. Cell values containing &, <, >, or quotes are escaped to XML entities so the output remains well-formed. The document starts with a standard UTF-8 XML declaration and is pretty-printed with indentation for readability.

Every column becomes a child element, not an attribute. If your target schema requires attributes (for example id="101" on the record tag), add them after conversion or post-process with a script. Nested collections (line items inside an order) are not inferred from a flat CSV — keep one entity type per file or build nesting in a second step.

How it works

The converter parses the CSV with comma-and-quote-aware logic, then builds an XML document by wrapping the dataset in your chosen root element and each row in your chosen record element.

Column headers become child element names. Headers with spaces are converted to underscores, and a leading underscore is added if a header starts with a digit, so the output is always valid XML regardless of the original column names.

Cell values are inserted as text content with &, <, >, and quote characters escaped to their XML entity equivalents. The whole document is pretty-printed with two-space indentation and prefixed with a UTF-8 XML declaration.

Common use cases

  • Generating XML import files for an enterprise system that rejects CSV uploads.
  • Creating XML test data from a spreadsheet for integration or QA testing.
  • Converting a product list CSV into XML for a legacy catalog or PIM feed.
  • Preparing XML records from a CSV export for a government reporting portal.
  • Producing sample payloads for EDI-style partners who document XML examples only.
  • Turning operations master lists maintained in Excel into XML for a scheduled importer.

How to use this tool

  1. Paste your CSV or upload a file, then set the root element and record element names if you want something other than the defaults.
  2. Review the sanitized column-to-element mapping so you can catch any header that will be renamed before relying on the full file.
  3. Compare one generated record against what your target system expects (tag names, field order, required columns).
  4. Copy or download the .xml file for your import, feed, or integration.
  5. If the importer requires namespaces or attributes, add those in a follow-up edit or script before the production run.

Example

Input CSV

id,name,price
101,Widget,9.99
102,Gadget,14.50

Output XML

<?xml version="1.0" encoding="UTF-8"?>
<records>
  <record>
    <id>101</id>
    <name>Widget</name>
    <price>9.99</price>
  </record>
  <record>
    <id>102</id>
    <name>Gadget</name>
    <price>14.50</price>
  </record>
</records>

Tips for best results

  • Rename CSV column headers to valid, descriptive XML names before converting when you care about the exact tag spelling.
  • Set root and record element names to match your target schema (items/item, products/product) instead of renaming later.
  • Trim unused columns so the XML stays shorter and easier to validate against a sample payload.
  • Preview one full record against your integration’s example XML before importing production volumes.
  • Keep the source CSV UTF-8 so accented characters survive into the XML text nodes.
  • Do not manually unescape &amp; or &lt; in the raw XML — those entities are correct and required.
  • For very wide sheets, confirm the target actually needs every column before converting the full file.

Common errors and how to fix them

A column header becomes an unexpected element name like _1code instead of code.
XML element names cannot start with a digit, so the converter prepends an underscore automatically. Rename the header in the CSV first (for example to code_1) if you need a specific element name in the output.
Special characters like & or < in a cell show up escaped as &amp; or &lt; in the raw XML.
That is correct, valid XML — those entities render back to the original character in any XML viewer or parser. Do not manually unescape them; doing so would produce malformed XML.
The target system rejects the file with a namespace or schema validation error.
Some systems require a specific xmlns attribute or a structure defined by an XSD schema that a generic converter cannot infer. Add the required namespace attribute manually after conversion, or check your integration's sample XML for the exact structure expected.
Very wide CSVs (50+ columns) produce XML that is hard to review.
This is expected — XML uses one element per column, which is inherently more verbose than CSV. Consider whether the target system actually needs every column before converting the full dataset.
Required fields are missing or named differently than the XSD expects.
Align CSV headers with the schema’s element local names before converting, and set the record/root tags to match the sample payload. Generic defaults (records/record) only work when the importer is flexible.
The XML looks fine but the importer says the document is empty or has zero records.
Confirm you used a header row plus at least one data row, and that the record element name matches what the importer queries. A mismatched wrapper tag often looks “valid” but fails business validation.

Best practices

  • Rename CSV headers to valid, descriptive XML element names before converting (letters, numbers, underscores, no spaces or leading digits).
  • Set a record element name that matches your target schema's expected tag (for example item instead of the default record) to avoid a manual find-and-replace afterward.
  • Keep the dataset limited to columns actually required downstream — trimming unused columns keeps the generated XML shorter and easier to validate.
  • Validate the output against your target system's XSD or a sample payload before running a real import.
  • Preserve a copy of the original CSV until the import succeeds, in case field mapping needs another pass.
  • Document root/record names and any post-conversion namespace edits so the next export is repeatable.
  • Convert a small sample first when the schema is unfamiliar — fix naming once, then run the full file.

What CSV to XML conversion actually does

CSV stores tabular data as plain text. XML stores structured documents as trees of elements and text. Moving from CSV to XML is a packaging step: you keep the same field values, but you express each row as a named record and each column as a named child so systems that speak XML can ingest the data.

This tool builds a shallow, regular tree. It does not invent nested line-item arrays, namespaces, or attributes from spreadsheet conventions. That keeps the mapping predictable for catalogs, contact lists, and simple masters — and keeps expectations clear when your target needs a richer schema.

Use it when you already maintain data in Excel or Google Sheets and an importer, portal, or partner only accepts XML. Once the tag names match their sample, generation is usually faster than hand-authoring records.

When to convert CSV to XML (and when not to)

Convert when the downstream system documents an XML upload, SOAP body, or file drop, and your source of truth is a spreadsheet. Convert when QA needs fixture XML from a table of cases. Convert when a legacy catalog still ingests product XML weekly.

Skip conversion if the partner already accepts CSV or JSON — prefer the format they natively support. Skip if you need deep nesting (orders with many lines) from a single flat sheet without a second transform. Skip if XSD validation with complex types is the real requirement; you will need a schema-aware pipeline.

A common pattern is: maintain the master in CSV, generate XML for the importer, and keep CSV as the editable source. That avoids fighting XML tooling for everyday edits.

  • Good fit: spreadsheet master → enterprise XML import, test fixtures, government portal uploads.
  • Poor fit: multi-level documents that must nest repeating children from one wide CSV.
  • Better as a script: recurring jobs with fixed XSD, namespaces, and automated delivery.

Root tags, record tags, and header-to-element mapping

The root element wraps the entire list. The record element wraps one CSV row. Child elements under each record come from the header row. Matching those three names to your sample XML is the highest-leverage step before a production import.

If the sample shows products/product/name, set root to products and record to product, and ensure a name column exists. Defaults (records/record) are fine for flexible tools and demos, but brittle against strict schemas.

Header sanitization keeps the document well-formed when spreadsheets use friendly labels. Prefer renaming headers upstream to the exact local names in the XSD so sanitization never surprises you.

Escaping, encoding, and well-formed output

XML text cannot contain raw & or < without escaping. The converter writes entities such as &amp; and &lt; so parsers accept the file. Seeing those entities in the raw text means the document is correct, not broken.

UTF-8 is assumed for modern interchange. Export CSV as UTF-8 from Excel or Sheets when you have non-ASCII content. A wrong source encoding produces garbled text nodes that no amount of tag renaming will fix.

The XML declaration advertises version 1.0 and UTF-8. Most importers accept that. If a partner insists on a different declaration or BOM policy, adjust after download according to their checklist.

Attributes, namespaces, and XSD expectations

This converter emits child elements for every column. It does not emit attributes on the record tag. Schemas that require <record id="101"> need a post-step: move a field into an attribute or generate with a scripted template.

Namespaces (xmlns) are often mandatory in enterprise XML even when the local element names look simple. Add the namespace on the root after conversion if your sample includes one. Without it, validation can fail even when the tree shape looks right.

XSD may also enforce order, nillable fields, or typed values. Treat browser conversion as structure generation; treat schema validation as a separate gate in your integration toolkit.

Nested data and multi-table models

A single CSV row is one shallow record. Parent/child relationships (invoice header + lines) usually need two files, a join key, or a script that groups rows. Do not expect one wide CSV with repeated column groups to become nested XML automatically.

If you must ship nested XML, convert the parent table first, convert children separately, then merge with a small transform — or maintain nested JSON/XML as the canonical form and use CSV only for human edits of leaf lists.

For catalogs where each product is flat (sku, name, price), this tool’s one-row-one-record model is exactly the right fit.

Preparing CSV in Excel and Google Sheets

Clean headers and consistent column counts matter more than fancy formatting. Remove blank trailing columns, ensure one header row, and export UTF-8 CSV. European locales that export semicolons should be normalized to comma-separated input before converting.

IDs and codes should stay text in the spreadsheet so leading zeros survive into XML text nodes. Dates should use an unambiguous format your importer expects (often ISO-8601).

If Excel corrupted values on open, fix them in the sheet and re-export before converting — the XML tool will faithfully carry whatever text is in the CSV.

Typical workflows

Enterprise import: download a template CSV, fill rows, convert with matching root/record names, validate against sample XML, upload.

QA fixtures: keep scenarios in a spreadsheet, regenerate XML when cases change, commit fixtures next to tests.

Partner feeds: operations edits prices in Sheets, converts weekly, drops XML on SFTP. Automate once the mapping is stable.

Migration: extract legacy tables to CSV, generate XML for the new system’s first load, then switch to native APIs if available.

Browser limits, privacy, and large files

Processing is local in the browser. Your CSV is not uploaded to Convert CSV servers for the transform. The website still loads normally and may use analytics or ads as described in the privacy policy.

Very large sheets produce large XML strings and can strain memory. Convert in batches, or use a server-side job for multi‑megabyte nightly loads.

For sensitive data, local conversion is preferable to unknown online APIs. Clear downloads on shared machines when finished.

CSV to XML versus writing a template script

A script or XSLT pipeline wins when namespaces, attributes, nesting, and validation are fixed requirements. Check it into source control and run it in CI.

The browser converter wins for one-off and exploratory work: paste, set tags, download, compare to a sample. Many teams prototype here, then harden into a script.

If you regenerate the same feed weekly with identical tags, that is the signal to automate.

Quality checklist before you upload

Confirm root and record names match the partner sample. Confirm child element names match required fields. Confirm row count matches your CSV data rows.

Open the XML in a viewer or validator. Check escaped entities look correct. Spot-check a row with &, quotes, or commas in the original cell.

If an XSD exists, validate before the production window. Keep the CSV backup until the import report is green.

  • Root/record tags match the target sample.
  • Headers map to expected element local names.
  • Declaration and UTF-8 look correct for non-ASCII data.
  • No manual unescaping of entities.
  • Sample validated; full file converted only after that.

Related tools and next steps

To flatten XML back into a spreadsheet, use the XML to CSV converter. For JSON APIs, prefer CSV to JSON. For human-readable config lists, CSV to YAML may fit better than XML.

Clean headers and rows in the Online CSV Editor before converting if your export is messy. Format guides on the site cover delimiters and encoding when the CSV itself is the problem.

Frequently asked questions

Can I choose my own root and record element names?

Yes — both are configurable on the tool; the defaults are records for the root and record for each row if you do not set your own.

What happens to column headers that aren't valid XML element names?

Spaces are converted to underscores and a leading underscore is added if the header starts with a digit, so every header becomes a valid element name automatically.

Does the output include an XML declaration?

Yes, every generated file starts with a standard <?xml version="1.0" encoding="UTF-8"?> declaration line.

Are CSV columns written as XML attributes?

No. This converter writes every column as a child element, not as an XML attribute. If you need attributes, add them manually after conversion or post-process the XML with a script.

Is my CSV data uploaded anywhere?

No. The conversion runs entirely in your browser — file contents are not sent to a server as part of the transform. See the Privacy Policy for site analytics and advertising.

How do I convert XML back to CSV?

Use the XML to CSV converter, which detects the repeating record element in an XML document and extracts it back into spreadsheet rows.

Can this add an xmlns namespace for me?

Not automatically. Generate the element tree here, then add the xmlns (and any schemaLocation) required by your partner sample before upload.

Will empty CSV cells omit the XML element?

Empty values still produce elements with empty text content so the structure stays consistent across records. Adjust afterward if your schema prefers omitted or nillable nodes.

Is there a file size limit?

There is no fixed server quota, but very large CSVs can slow or exhaust the browser. Convert in batches for bulk jobs.

Does the tool validate against an XSD?

No. It produces well-formed XML from your table. Run XSD validation in your integration tools when schema compliance is required.

Why did my header Product Name become Product_Name?

Spaces are not allowed in XML element names, so they are replaced with underscores. Rename headers to the exact schema names before converting if you need a specific spelling.

Can I create nested line items from one CSV?

Not with this flat mapping. Use separate files or a scripted transform to nest children under a parent record.

For more background on data formats and conversion workflows, read our format guides or browse the converter blog for step-by-step walkthroughs linked to each tool.