Xml.Document
Accessing DataParses XML content into a nested table structure.
Syntax
Xml.Document(contents as any, optional encoding as nullable number) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
contents | any | Yes | The XML text or binary content to parse. |
encoding | number | No | The text encoding of the content (e.g., TextEncoding.Utf8). |
Return Value
table — A table representing the XML document structure.
Remarks
Xml.Document parses XML content and returns a nested table representing the document structure. Each element in the XML becomes a row with the following columns:
| Column | Type | Description |
|---|---|---|
Name | text | The element tag name. |
Namespace | text | The XML namespace URI (empty string if none). |
Value | text | The text content of the element (null if it contains child elements). |
Attributes | table | A table of attribute name-value pairs for the element. |
[Children] | table | A nested table containing child elements, with the same column structure. |
Working with nested XML
Because XML is hierarchical, the result is deeply nested. You typically need multiple expansion steps:
1. Parse the XML to get the root-level table. 2. Filter or select the element you need by Name. 3. Expand the child table to drill deeper. 4. Repeat until you reach the leaf data.
Typical pattern
let
Source = Xml.Document(File.Contents("C:\Data\orders.xml")),
Root = Source{0}[Value], // drill into root element
Orders = Root{[Name = "Orders"]}[Value], // navigate to Orders node
Expanded = Table.ExpandTableColumn(Orders, "Value", {"Name", "Value"})
in
ExpandedNotes
- For large XML files, consider using
Xml.Tablesinstead, which provides a flattened view more suitable for tabular consumption. - Attributes are returned as a separate nested table on each element. Use
Table.ExpandTableColumnon theAttributescolumn to access them. - Namespace-aware XML requires matching on the
Namespacecolumn when filtering elements.
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks