Excel or CSV file to XML - ADF

Santhi Dhanuskodi 365 Reputation points
2024-02-26T06:42:22.1933333+00:00

Hi, I want to convert excel/csv file into XML format. This xml is used as a body text for a rest api.

Basically i need to send excel data to a REST API using ADF. Rest API accepts xml format. excel file is present in storage container.

What are the possible ways to achieve this? Python script or data flow has inbuilt support excel to xml conversion? any other ways? If using python script, what are the dependancies for executing python script? what are the infra requirements for the same? From where this script will run and how?

Azure Data Factory
Azure Data Factory

An Azure service for ingesting, preparing, and transforming data at scale.

Microsoft 365 and Office | SharePoint | For business | Windows

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 43,046 Reputation points MVP Volunteer Moderator
    2024-02-26T09:44:40.4266667+00:00

    XML format is supported for the following connectors: Amazon S3, Amazon S3 Compatible Storage, Azure Blob, Azure Data Lake Storage Gen1, Azure Data Lake Storage Gen2, Azure Files, File System, FTP, Google Cloud Storage, HDFS, HTTP, Oracle Cloud Storage and SFTP. It is supported as source but not sink. Consider exploring the "Transform XML" feature in Azure Logic Apps to see if it aligns with your needs :

    1. A guide on using Azure Logic Apps for importing CSV files to SQL Server: http://blogs.recneps.net/post/Using-Azure-Logic-Apps-to-Import-CSV-to-SQL-Server
    2. A discussion on Stack Overflow about converting CSV to XML in Logic Apps: https://stackoverflow.com/questions/61417713/how-to-convert-a-csv-to-xml-in-logic-apps
    3. A forum post on MSDN about converting CSV/Excel to XML in Logic Apps: https://social.msdn.microsoft.com/Forums/en-US/dfce78db-ebd6-41d9-ac7b-423a1f83f186/convert-csvexcell-to-xml-in-logic-app Additionally, it's strongly encouraged to support existing feature requests on the ADF User Voice forum by upvoting or commenting. This can help prioritize the development of features such as:
    • XML support at the sink side
    • Support for XML files for ADLS as a sink If you have the possibility to use python :
    import pandas as pd
    import xml.etree.ElementTree as ET
    
    # Load the Excel/CSV file
    df = pd.read_csv('path_to_your_file.csv')
    
    # Convert the DataFrame to XML format
    root = ET.Element("Root")
    for _, row in df.iterrows():
        record = ET.SubElement(root, "Record")
        for col in df.columns:
            child = ET.SubElement(record, col)
            child.text = str(row[col])
    
    # Convert the XML tree to a string
    xml_str = ET.tostring(root, encoding='utf8', method='xml')
    
    # Save or use the XML string as needed
    
    

    Was this answer helpful?

    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    2 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.