Function Repository Resource:

XMLToTabular

Source Notebook

Import XML data in a rectangular format

Contributed by: Sjoerd Smit

ResourceFunction["XMLToTabular"][file]

imports XML from file and converts it to Tabular data.

ResourceFunction["XMLToTabular"][str]

imports XML from string str.

ResourceFunction["XMLToTabular"][xml]

converts an XMLObject or XMLElement into Tabular data.

Details

The XML tags will be converted to ExtendedKey headings in the Tabular data.
If an XMLElement has multiple data elements, ResourceFunction["XMLToTabular"] will add a "Grouping" column and an "Index" column for this sequence of data so that the data can be grouped again later if necessary.

Examples

Basic Examples (1) 

Import an XML file:

In[1]:=
file = FindFile["ExampleData/paintings.xml"];
ResourceFunction["XMLToTabular"][file]
Out[2]=

Scope (3) 

Import XML data from a raw String:

In[3]:=
xmlstring = Import["ExampleData/methane.xml", "String"];
Snippet[xmlstring]
Out[4]=
In[5]:=
ResourceFunction["XMLToTabular"][xmlstring]
Out[5]=

Import XML from and XMLObject:

In[6]:=
xml = Import["ExampleData/ALHitters.xml", "XML"];
xml // Short
Out[7]=
In[8]:=
tab = ResourceFunction["XMLToTabular"][xml]
Out[8]=

Find the baseball players with the longest names:

In[9]:=
Normal@TakeLargestBy[tab[All, "PLAYER"], StringLength, 10]
Out[9]=

Import a webpage to Tabular:

In[10]:=
ResourceFunction["XMLToTabular"][
 Import["https://www.wolframcloud.com", "XMLObject"]]
Out[10]=

Publisher

Sjoerd Smit

Requirements

Wolfram Language 14.0 (January 2024) or above

Version History

  • 1.0.0 – 30 July 2025

Related Resources

License Information