Initializing playground…
← Back to roadmap

📄 readXml & toXml — Interactive Playground

Parse XML text into a DataFrame with auto-detection of row elements, attribute and child-element columns, entity decoding, CDATA support, namespace stripping, and numeric coercion. Serialize any DataFrame back to well-formed XML with full formatting control. Mirrors pandas.read_xml() and pandas.DataFrame.to_xml().
Edit any code block below and press ▶ Run (or Ctrl+Enter) to execute it live in your browser.

1 · Basic readXml — child-element rows

The most common XML layout: a root element containing repeating row elements, each with child elements as columns. readXml auto-detects the row tag and coerces numeric strings automatically.

TypeScript
Click ▶ Run to execute

2 · Attribute rows

XML elements can carry data as attributes instead of (or in addition to) child elements. Use attribs: true (the default) to include them.

TypeScript
Click ▶ Run to execute

3 · usecols, nrows, indexCol

Restrict the columns returned with usecols, limit rows with nrows, and promote a column to the index with indexCol.

TypeScript
Click ▶ Run to execute

4 · naValues — custom NA strings

Built-in NA strings include "", "NA", "NaN", "N/A", "null", "None", "nan". Use naValues to add your own.

TypeScript
Click ▶ Run to execute

5 · Entities & CDATA

Named entities (&amp;, &lt;, …), decimal/hex character references (&#65;, &#x41;), and CDATA sections (<![CDATA[…]]>) are all handled transparently.

TypeScript
Click ▶ Run to execute

6 · toXml — child elements (default)

toXml(df) produces a well-formed XML document with an XML declaration, a configurable root element, and one child element per row containing one sub-element per column.

TypeScript
Click ▶ Run to execute

7 · toXml — attribs mode

Set attribs: true to emit column values as XML attributes on each row element instead of as child elements — produces more compact output.

TypeScript
Click ▶ Run to execute

8 · toXml — namespaces & CDATA columns

Declare XML namespace prefixes on the root element with namespaces. Wrap sensitive columns in CDATA sections with cdataCols to preserve special characters literally.

TypeScript
Click ▶ Run to execute

9 · Round-trip: toXml → readXml

Serializing a DataFrame to XML and reading it back should produce an identical DataFrame (shape and values).

TypeScript
Click ▶ Run to execute