1

I'm trying to save the string content into azure data lake as XML content.

a string variable contains below mentioned xml content.

<project> <dateformat>dd-MM-yy</dateformat> <timeformat>HH:mm</timeformat> <useCDATA>true</useCDATA> </project> 

i have used the below code to process the file into data lake.

xmlfilewrite = "/mnt/adls/ProjectDataDecoded.xml" with open(xmlfilewrite , "w") as f: f.write(project_processed_var) 

it throws the following error: No such file or directory: '/mnt/adls/ProjectDataDecoded.xml"

I'm able to access the data lake by using the above mounting point but unable do with the above function "open".

can anyone help me?

2 Answers 2

3

Issue is solved.

In databricks when you have a mount point existing on Azure Data Lake,we need to add "/dbfs" to the path and pass it to OPEN function. The issue is solved by using below code

xmlfilewrite = "/dbfs/mnt/adls/ProjectDataDecoded.xml" with open(xmlfilewrite , "w") as f: f.write(project_processed_var) 
Sign up to request clarification or add additional context in comments.

Comments

0

You could try using the Spark-XML library. Convert your string to a dataframe where each row denotes one project. Then you can write it to ADLS in this way.

df.select("dateformat", "timeformat","useCDATA").write \ .format('xml') \ .options(rowTag='project', rootTag='project') \ .save('/mnt/adls/ProjectDataDecoded.xml') 

Here is how you can include an external library -https://docs.databricks.com/libraries.html#create-a-library

1 Comment

i have tried to save the \XML as suggested but it saves in a different format as shown below. ``` <ROWS> <project> <ProjectData>&lt;project&gt; &lt;dateformat&gt;dd-MM-yy&lt;/dateformat&gt; &lt;timeformat&gt;HH:mm&lt;/timeformat&gt; &lt;useCDATA&gt;true&lt;/useCDATA&gt; </ProjectData> </project> </ROWS> ``` Could you please provide me how to convert the string to data frame.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.