Search code examples
pythonxmlazure-synapseazure-data-lakexmlwriter

To write an xml string to azure data lake storage


When I try to write an xml string to azure datalake storage I am getting error as file not found. I am using synapse notebook with python to write the file. Synapse notebook and the datalake storage are in the same resource group

I tried with to_xml({file_path/output.xml}). But this does not work with xml strings


Solution

  • If you use pandas, what I assume you use it:

    import pandas as pd
    import io
    xml = '''<data><row><tex>text example</tex></row></data>'''
    
    df = pd.read_xml(io.StringIO(xml))
    print(df)
    
    # Output in file
    out ='StringXML.xml'
    df.to_xml(f'{out}', index=False)
    

    This will write into file:

    <?xml version='1.0' encoding='utf-8'?>
    <data>
      <row>
        <tex>text example</tex>
      </row>
    </data>