Acquire / file · All operations

Read an XML or HTML file

Read XML, HTML tables.

Status

In arcform

Runs as a SQL step

arcform carries it as a sql: step today, with the webbed extension.

Shape of the result
a new table, from no input table
Level
needs a DuckDB extension

The DuckDB step

Parse XML into rows

SQL
INSTALL webbed FROM community; LOAD webbed;
COPY (SELECT '<rows><r><id>1</id><v>a</v></r><r><id>2</id><v>b</v></r></rows>' AS x) TO '<your_scratch_dir>/t.xml' (FORMAT csv, HEADER false, QUOTE '');
CREATE TEMP TABLE result AS
SELECT * FROM read_xml('<your_scratch_dir>/t.xml');
SELECT * FROM result;
SELECT CASE WHEN ((SELECT count(*) = 2 AND list(v ORDER BY id) = ['a', 'b'] FROM result)) THEN 'as expected' ELSE error('the two elements did not become two rows') END AS verdict;

Replace <your_scratch_dir> with a directory of your own that you can write to before running the statement.

  • The statement writes t.xml itself, in <your_scratch_dir>.
  • It needs the webbed extension.
  • The statement checks its own result and raises an error when it is wrong: “the two elements did not become two rows”.
  • It passed on DuckDB v2.0.0 (Cyanoptera) d54cbbe3df.

Variants

Stream a very large XML file

Read an XML file too large to hold in memory as a stream of element events.

Read rows from an XML file

Turn the elements of an XML document into rows and columns, picking rows and fields by path.

What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

Apache Hop (2)
  • Get Data From XMLread 2026-09-27

    Read XML from files or a field, extracting rows and fields with XPath

  • Read very large XML files as a stream of element events with the StAX parser

Apache NiFi (2)
AWS Glue (1)
  • XML (read)read 2026-09-27

    Read XML data from Amazon S3 and other supported connection types

Azure Data Factory (1)
Duckle (2)
  • HTMLread 2026-09-25

    rows from an HTML page or table by CSS selector

  • XMLread 2026-09-25

    one row per element matched by a slash-separated row path

EasyMorph (1)
KNIME Analytics Platform (1)
  • XML Readerread 2026-09-27

    Read an XML file into an XML column

OpenRefine (1)
  • XMLread 2026-09-27

    Read XML into rows and columns

Pentaho Data Integration (2)
Power Query M (4)
  • Html.Tableread 2026-09-27

    Build a table from HTML by running a CSS selector per column, with an optional row selector

  • Web.Pageread 2026-09-27

    Break an HTML document into its tables and other structures, plus its text with tags removed

  • Xml.Documentread 2026-09-27

    Parse an XML document into a hierarchical table of elements

  • Xml.Tablesread 2026-09-27

    Parse an XML document into a nested collection of flattened tables

RapidMiner Studio (2)
  • Read XMLread 2026-09-27

    Read an XML file into a table using XPath expressions for rows and columns

  • Read XRFFread 2026-09-27

    Read an XRFF (XML form of ARFF) file into a table

Talend (3)
  • tFileInputMSXMLread 2026-09-27

    Read an XML file holding several record structures, one output schema per structure

  • tFileInputXMLread 2026-09-27

    Read an XML file row by row into fields

  • tFileStreamInputXMLread 2026-09-27

    Read an XML file row by row into fields in a Spark Streaming Job

VisiData (2)
  • html (loader)read 2026-09-23

    Load HTML tables, one sheet per table; also filetype htm

  • xml (loader)read 2026-09-23

    Load XML; also filetype svg

Background

In pandas, read_xml parses an Extensible Markup Language (XML) document from a file, URL or string and returns its content as a table, a DataFrame.[1] In pandas, read_xml selects nodes by an expression and maps each selected node's child elements and attributes to columns.[1]

When to use it

XML is a textual data format, and although its design focuses on documents, it is widely used to represent arbitrary data structures such as those used in web services.[2] In pandas, read_xml is best designed for shallow XML documents, in which a root holds repeated row elements whose child elements hold the column values.[1] Because an XML document may lay out its elements and attributes in any way the specifications allow, pandas treats read_xml as a convenience handler for a flatter design, not for every possible XML structure.[1] Before reading a file, find the element that repeats once per record: that element is the row, and what sits inside it is the set of candidate columns. (Meridian's view)

In AWS Glue, the XML reader names attribute fields with a prefix, an underscore by default, to tell them apart from child element text.[3] In Azure Data Factory, the attributes of an XML element are parsed as subfields of the element, named in the pattern @attributeName.[4] In Azure Data Factory, when an XML element has both a simple text value and attributes or child elements, the text is parsed into a value column named _value_.[4] Expect attribute and text columns to arrive under names the reader chose, and rename them once, straight after reading, rather than carrying the reader's conventions into every later query. (Meridian's view) In pandas, when an XML document uses a default namespace declared without a prefix, a temporary prefix such as doc must be assigned to that namespace before its nodes can be parsed.[1]

A text that violates XML's well-formedness rules is not XML, and an XML processor that encounters such a violation is required to report the error and cease normal processing.[2] When an XML file will not load at all, check that it is well-formed before changing how it is read. (Meridian's view)

Document Object Model (DOM) implementations tend to be memory intensive, because they generally load the entire document into memory as a tree of objects before allowing access.[2] For XML files of hundreds of megabytes to gigabytes, pandas read_xml offers an iterparse option that extracts chosen elements and attributes without holding the entire tree in memory.[5] In Apache Hop, the XML Input Stream transform reads XML with a Streaming API for XML (StAX) parser and is recommended for fast loads that are independent of memory whatever the file size.[6]

The method

XML Path Language (XPath) is an expression language designed to support the query or transformation of XML documents, defined by the World Wide Web Consortium (W3C) in 1999.[7] XPath is based on a tree representation of an XML document and can navigate around the tree, selecting nodes by a variety of criteria.[7] XPath 1.0 became a W3C Recommendation on 16 November 1999, and XPath 1.0 is still the version that is most widely available.[7] In Apache Hop, Get Data From XML adds one output row for every entry that matches its Loop XPath, the main setting used to flatten the file, and reads each field by an XPath of its own.[8] In AWS Glue, the XML reader takes the tag of the element to treat as a row, examines the elements with that tag to infer a schema, and fills its output with their values.[3] Extensible Stylesheet Language Transformations (XSLT) is a declarative language originally designed for transforming XML documents into other XML documents or other formats.[9] In pandas, read_xml can apply an XSLT 1.0 stylesheet that flattens a deeply nested document, and its XPath must then point at nodes of the transformed document, not the original.[1]

StAX has its roots in a number of incompatible pull interfaces for XML, most notably XMLPULL.[10] In Apache Hop, the XML Input Stream (StAX) transform moves the processing logic into the pipeline, providing the raw XML data stream together with additional processing information.[6] In Apache Hop, the XML Input Stream (StAX) transform can label each item it emits with an XML data type, such as START_ELEMENT, END_ELEMENT or ATTRIBUTE.[6]

Compared with the alternatives

XML's error policy, occasionally called draconian error handling, contrasts with programs that process Hypertext Markup Language (HTML), which are designed to produce a reasonable result even with severe markup errors.[2][11]