How to parse XML data enclosed in nvarchar datatype using Azure datafactory

Shiva 0 Reputation points

Hello, I have xml data enclosed in nvarchar datatype, I need respective data to be mapped to new columns Catalog Name and RequireApprove, Could anyone help on this using Azure Data Factory. sample xml data,  <catalogs><Catalog
</catalogs>   Thank you

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,554 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,896 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sedat SALMAN 13,265 Reputation points

    In Azure Data Factory, you can use the Mapping Data Flows feature to parse XML data stored in an nvarchar column and map it to new columns.

    • Create a new pipeline in Azure Data Factory.
      • Add Copy Data Activity
    • Set up the source dataset:
      • Create a new dataset for your source data (e.g., SQL Server, Azure Blob Storage, etc.).
      • Set the data type of the column containing the XML data as nvarchar.
      • Import the schema or enter it manually, making sure the column containing the XML data is included.
    • Set up the sink dataset:
      • Create a new dataset for your destination data (e.g., SQL Server, Azure Blob Storage, etc.).
      • Define the schema with the new columns "Catalog Name" and "RequireApprove" along with their respective data types (e.g., nvarchar for Catalog Name and bit for RequireApprove).
    • Configure the mapping:
      • In the "Copy Data" activity, click the "Mapping" tab.
      • For each new column ("Catalog Name" and "RequireApprove"), click "Add dynamic content" and use the following expressions:
        • Catalog Name: @XPath(xml(columnName), 'string(/catalogs/Catalog/@Name)')
        • RequireApprove: @XPath(xml(columnName), 'string(/catalogs/Catalog/@RequireApprove)') Replace columnName with the name of the column containing the XML data in your source dataset.
    • Configure the settings of the "Copy Data" activity as needed, such as concurrency, fault tolerance, etc.
    • Publish the changes to your Azure Data Factory and trigger the pipeline to run. This will parse the XML data from the nvarchar column in the source dataset and map the Catalog Name and RequireApprove attributes to the corresponding columns in the sink dataset.

  2. ShaikMaheer-MSFT 38,301 Reputation points Microsoft Employee

    Hi Shiva,

    Thank you for posting query in Microsoft Q&A Platform.

    From the error screenshots, it seems its type mismatch. That means your expression may expecting some type but you are supplying some other type. Kindly check the types of values which you are passing in to xpath() and xml() functions.

    Check below links to understand about these functions with examples.



    Hope this helps. Please let me know how it goes.

    Please consider hitting Accept Answer button. Accepted answers help community as well.