cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

How do we pass the row tags dynamically while reading a XML file into a dataframe?

Stita
New Contributor II

I have a set of xml files where the row tags change dynamically. How can we achieve this scenario in databricks.

df1=spark.read.format('xml').option('rootTag','XRoot').option('rowTag','PL1PLLL').load("dbfs:/FileStore/tables/ins/")

We need to pass a value dynamically in place of PL1PLLL option('rowTag','PL1PLLL')

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

If it is dynamically for the whole file, you can just use variable

tag = 'PL1PLLL'
df1=spark.read.format('xml').option('rootTag','XRoot').option('rowTag' ,tag).load("dbfs:/FileStore/tables/ins/file.xml")

View solution in original post

3 REPLIES 3

Kaniz
Community Manager
Community Manager

Hi @Stitapragna B​, In this article, It will explain how to read an XML file with several options using the Scala example. Please let me know if that helps, or else we'll find an alternative answer for you.

Kaniz
Community Manager
Community Manager

Hi @Stitapragna B​ ​, We haven’t heard from you since the last response from me, and I was checking back to see if you have a resolution yet.

If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

Hubert-Dudek
Esteemed Contributor III

If it is dynamically for the whole file, you can just use variable

tag = 'PL1PLLL'
df1=spark.read.format('xml').option('rootTag','XRoot').option('rowTag' ,tag).load("dbfs:/FileStore/tables/ins/file.xml")

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.