Working with Embedded XML Content in an ETL Process

23 February 2023
KingswaySoft Team

KingswaySoft offers XML Source/Extract components that can easily parse out an XML structure to a tabular format, either from an API endpoint response, a file, or a column. The components work on the basis of a pre-imported document designer, which would recognize XML structures in the source data, and parse them out accordingly. There are cases in which the XML that we receive from an API response/file is a mix of regular XML characters, as well as escaped characters. In such cases, it is important that they are properly handled and transformed, to then parse through them successfully. The problem lies in the fact that the document designer is static, and we would need an additional XML extract component to recognize the escaped XML design and parse that node out successfully. In this blog post, we will be looking at an example of this situation. Below you can see the components you will need, all available as part of our SSIS Productivity Pack:

Design

Let's take an XML body that is a mix of escaped and un-escaped characters, as shown below. This is a preview of the response body using our HTTP Connection manager.

XMLDesign.png

The first step would be to have the XML design, the original one, imported into the document designer of the XML Source component. Open the component, and on the document designer page, choose the import from XML(web) option. As you can see, the "Result" node is detected as a "ntext" column, as it has the escaped portion.

ResultNode.png

The next thing to do is use the Premium Derived Column component in the data flow, and un-escape the XML node, Result. This can be achieved by using the function as shown below. Then, provide a name to the derived column; this is what you would be using in the XML Extract component later to parse the values out.

DerivedColumn.png

Now, further down, you would need the XML Extract component. But before that, we need a design for it. That is, in order to have the document designer for the XML extraction from the Result node, its un-escaped form needs to be provided. To achieve this, either the Premium Derived column function, "WriteTextContent( «file_path», «text» )" can be used to write the un-escaped node to a file path.


Another way to do this would be by using an online tool to un-escape the XML. This can be copied and pasted to a file, and saved with an XML extension.

UnescapeXml.png

This file can be imported to the XML Extract component, by using the "XML (Local File)" option, which will have the child nodes in the Result node detected as expected. Based on this, you could modify the node types, have them as columns or outputs, and have them parsed out. Then, once you have the design, click on the "Additional Settings: tab on the 'Document Designer" page, and choose the new Derived Column that you had set up in the previous step. This would make sure that you have the right input coming in.

XMLExtract.png

Additional Settings.png

The final design flow would look as shown below:

Data Flow.png

Another case worth mentioning is: if you have other parent nodes in the original XML Source component that need to be joined with the "Result" node that is handled in the XML extract - This can be easily achieved by using the out of the box Sort and Merge join components, or by using a Premium Lookup component. The design may look similar to the one shown below. We have more details in the following blog post: Joining Parent and Child Records Efficiently.

Parent child design.png

Conclusion

By following the above process, varying XML designs, such as the one discussed, can easily be handled. XML Source and XML Extract work in a similar pattern except for the fact that XML Extract is a transformation component that requires an input.

We hope this has helped!

Archive

November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags