R XML Files

XML stands for Extensible Markup Language. It is a file format which shares both file format and data on the WWW, intranets, and elsewhere using ASCII text. It is a popular choice for storing large amounts of complex data. It is very similar to HTML it contains markup tags.

HTML describes the structure of the page, and XML tags describe the meaning of the data contained into the file.

Install the XML Package

To read the XML file in R, use the “XML” package.  To install this package, use the following command:

Create an XML file

To create an XML file copy the below data or create your own data into a text editor like notepad and save this file with .xml extension. Here, my file name is Student.xml.

Reading XML File

To read the xml file “XML” package provides a function called xmlParse().

Example:

Output:

Find the Number of Nodes Present in XML File

Output:

Get the details of the first node

Example:

Output:

Get Different Elements of a Node

Example:

Output:

Convert XML to Data frame

xmlToDataFrame() function is used to convert the XML file into data frame.

Example:

Output:

Reference:

https://stackoverflow.com/questions/35181106/parsing-xml-to-r