DEV Community


R Language : Read XML files In R

maheshkay profile image Mahesh K Updated on ・1 min read

Let's discuss how to Read XML Files in R. There are many places where people make use of the XML data. Often some specific set of data is being stored into the XML.

Prior to JSON files getting popular as they are today, many companies used to offer the XML export option. So you are going to find many legacy files that store the data in XML file. So we are going to see how to read this data with the R language.

You can watch the video instruction of the tutorial - How to Read XML Files in R.

XML Package

In order to read the XML file and to manipulate the data, you need to make use of the XML package. You can install the package with the following code.


So let's assume we have XML file named mydata.xml. You can get the XML data from sample file.

Now we can get started to import the package.


Next package that we would be needing to be added is the following.


Let's name the input file and import the file.

dt <- xmlParse(file = "mydata.xml")

So here's the data variable named "dt". You can print the output as follows.


Here's the output that you'd get in the console.

<name>Belgian Waffles</name>

I hope this post helps you to read the XML data from the file in R language.


Editor guide
mccurcio profile image
Matt Curcio

Good start, but how does one get the specific information? How do you choose the info would be good to add too. :))