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.
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.
XML elements can carry data as attributes instead of (or in addition to) child
elements. Use attribs: true (the default) to include them.
Restrict the columns returned with usecols, limit rows with
nrows, and promote a column to the index with indexCol.
Built-in NA strings include "", "NA", "NaN",
"N/A", "null", "None", "nan".
Use naValues to add your own.
Named entities (&, <, …), decimal/hex
character references (A, A), and
CDATA sections (<![CDATA[…]]>) are all handled transparently.
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.
Set attribs: true to emit column values as XML attributes on each
row element instead of as child elements — produces more compact output.
Declare XML namespace prefixes on the root element with namespaces.
Wrap sensitive columns in CDATA sections with cdataCols to preserve
special characters literally.
Serializing a DataFrame to XML and reading it back should produce an identical DataFrame (shape and values).