Parse XML string in Azure Dataflow

Quyen Dang 21 Reputation points
2023-08-24T12:48:35.0033333+00:00

I have an XML file stored as a string as follow

<offices result="1">      
<office name="Company A" shortname="A">ABC01</office>   
<office name="Company B" shortname="B">ABC02</office>   
<office name="Company C" shortname="C">ABC03</office>   
</offices>

I want to parse this string using Parse step in Azure Dataflow into 3 columns consecutively, name, shortname, and ID (which is the ABC01 code). At the moment I can only take 2 columns name and shortname using this expression in Output column type

(offices as ({@result} as integer,
        office as ({@name} as string,
                    {@shortname} as string)[]))

How can I edit this to add the code in as well?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,625 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Amira Bedhiafi 33,071 Reputation points Volunteer Moderator
    2023-08-25T00:45:15.3933333+00:00

    For the provided XML content, you can use an expression that adds the content of the <office> tag to the parsed output.

    Your expression might look something like this:

    (offices as ({@result} as integer,
            office as ({@name} as string,
                        {@shortname} as string,
                        $value as string)[]))
    

    Here $value is used to grab the content of the <office> tag, which should give you the desired code (for example"ABC01").

    1 person found this answer helpful.

  2. AnnuKumari-MSFT 34,556 Reputation points Microsoft Employee Moderator
    2023-08-31T09:30:08.1133333+00:00

    Hi Quyen Dang ,

    Thankyou for using Microsoft Q&A platform and thanks for posting your question here.

    As per my understanding, you want to convert xml properties into columns using dataflow. Please let me know if that is not the case.

    Instead of parse , you can use flatten transformation and unroll by 'office' array and select the columns from the dropdown and give suitable names for the flattened columns

    User's image

    User's image

    Learn more about parse and flatten transformation here:

    Parse Transformation in Mapping Data Flow in Azure Data Factory

    Flatten Transformation in Mapping Data Flow in Azure Data Factory

    Hope it helps. Please accept the answer by clicking on Accept answer button. Thankyou


Your answer

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