cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

can we read XML files into Dataframes in Spark?

Srikanth_Gupta_
Valued Contributor
 
4 REPLIES 4

Ryan_Chynoweth
Esteemed Contributor

Yes, you can use the Spark XML library. https://github.com/databricks/spark-xml

Srikanth_Gupta_
Valued Contributor

Yes we can read using below code snippet

val df = spark.read .format("com.databricks.spark.xml").option("rowTag", "<message>") .load("sample.xml")

display(df)

rowTag is important to specify to read the actual content in XML

please read for more details

Mooune_DBU
Valued Contributor

Yes of course, you can use the

OR use

val df = spark.read
      .format("xml")
      .load("my_file.xml")

More info on the spark-xml api here

sean_owen
Databricks Employee
Databricks Employee

Note that you will need to install the spark-xml library to make this work: https://github.com/databricks/spark-xml For example you can create a Library in the workspace that references com.databricks:spark-xml_2.12:0.12.0 and then attach it to a cluster

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group