How does automatic XML record detection pick the table rows?
Dropping an .xml file onto the page transfers its bytes to a dedicated Web Worker, decodes UTF-8 text, and walks the element tree from the top down to convert XML to tabular CSV rows accurately.
Breadth-first scanning with 10x structured-element weighting
Real-world XML exports often contain nested lists inside each record, such as multiple <item> elements inside each <order>. A naive parser that picks the deepest or most frequent tag would split one order across three rows and discard the customer header.
Under the W3C Extensible Markup Language (XML) 1.0 Specification, elements form a strict hierarchical tree. The findRecords() scanner walks breadth-first from the root so shallower record containers (<orders>/<order>) are evaluated first, multiplying structured element groups by a 10× score factor.
It also guards against single-record objects that happen to contain one repeated scalar list alongside unique fields like <name>. Before converting complex feeds, you can inspect and indent raw XML markup before converting to confirm which tag represents your target row unit.
Unwrapping single-record containers and skipping namespaces
When an XML document contains only one record wrapped in outer container tags such as <shop><orders><order id="1">...</order></orders></shop>, the parser unwraps pure wrapper nodes until it reaches the record itself. It strips namespace prefixes (ns:order becomes order) and skips xmlns declarations so column headers stay readable.
If a file contains zero XML elements or yields zero extractable fields, the worker throws a clear error message rather than exporting a blank file.
Flattening attributes, nested XML elements, and repeated tags
Once the repeating record nodes are identified, every record is flattened into a uniform column map without losing attributes or deep hierarchy. Missing fields in sparse records become empty cells so every row aligns cleanly.
Mapping @attributes and parent/child element paths
The recursive flatten() pass visits each record’s attributes and child nodes in document order. Attributes become @attribute at the record root or child/@attribute when nested, while nested elements join tag names with / (customer/address/city).
- Scalar leaf tags: Simple child elements with text and no own attributes map directly to their tag name or nested slash path.
- Mixed text and attributes: When an element holds both text and attributes, its text content maps to the parent path while attributes map to
path/@attr.
Joining repeated child values and padding uniform row widths
If a single record repeats the same child tag (such as two <tag> elements), appendField() joins them with "; " inside that column instead of dropping earlier values. Every row is then padded to the widest column count across all records.
According to the IETF RFC 4180 CSV Format Specification, fields containing commas, double quotes, or line breaks must be wrapped in double quotes with internal quotes doubled (""), and lines end with CRLF (\r\n). This exporter applies RFC 4180 quoting strictly, and you can send the output to a browser-based CSV to PDF converter when you need a printable report.
| XML structure | Flattened CSV column | Example cell output |
|---|---|---|
<order id="104"> |
@id |
104 |
<customer><name>Ada</name></customer> |
customer/name |
Ada |
<item sku="B2">Widget</item> |
item and item/@sku |
Widget and B2 |
<tag>a</tag><tag>b</tag> |
tag |
a; b |
| Missing optional tag in row 2 | notes |
Empty string "" (uniform row width) |
UTF-8 BOM encoding and CSV formula injection protection
Exporting raw comma-separated text often breaks in two ways when opened by colleagues: garbled non-ASCII characters in Microsoft Excel and dangerous formula execution from untrusted strings. Both safeguards run automatically on every export.
Why prepending U+FEFF prevents Excel character corruption
Every generated .csv file starts with the 3-byte UTF-8 Byte Order Mark (\ufeff) before the header row. Without that marker, desktop spreadsheet programs on Windows frequently guess a legacy 8-bit code page and corrupt accented names, euro symbols, or CJK text.
Neutralizing dangerous formula prefixes in exported cells
Under the OWASP CSV Injection Prevention Guide, spreadsheet applications evaluate cell strings starting with =, +, -, or @ as executable formulas. When sanitizeFormulas is enabled on data rows, any string beginning with =, +, @, |, or a non-numeric - (even after leading whitespace) is prefixed with a single quote (').
Negative numbers such as -42.50 remain untouched so numeric columns stay usable. For multi-megabyte XML exports that produce too many rows for one sheet, you can break oversized CSV exports into smaller chunks immediately after conversion.
How to convert XML to CSV online without software vs XML to Excel
Plain CSV remains the universal interchange format for databases, Python scripts, and command-line pipelines, while native Excel workbooks preserve cell data types and column widths automatically. Because the entire parser runs inside your browser’s Web Worker, you can convert XML to CSV online without software or desktop spreadsheet suites installed.
As noted in the Unicode UTF-8 Byte Order Mark FAQ, BOM-prefixed UTF-8 files work cleanly in Excel and modern text editors, though some strict Unix command-line parsers expect BOM-free input. When your recipients need formatted spreadsheets with bold headers, auto-fitted column widths, and protected leading-zero IDs, convert directly with XML to Excel instead.
Every step from UTF-8 decoding to RFC 4180 quoting and OWASP formula neutralization finishes in local memory without touching a server. That makes it safe to process payroll exports, customer directories, and API logs directly in your tab.
Tip: Both converters run inside the same off-main-thread Web Worker, so click Convert to CSV for lightweight database imports or switch to
.xlsxwhenever you want numeric types and auto-sized columns preserved.