XML Edit in SSIS using Script task

48 Views Asked by At

Trying to include element in an xml which already contains data. The File needs to be processed part of a ssis package to bring in information on the server. Example of the xml file structure - I have included a subset of the xml where I am facing issue -

<ReportA>
    <Header>
        <Area>M</Area>
    </Header>
    <Year>2024</Year>
    <Type>A</Type>
    <Category>
    </Category>
</ReportA>

Using SSIS data flow task to read the XML it does not read the below, because it not nested with an element tag (minus the root element) 2024 A

Happy to share more information.

Expect all information to be read including Year and Type to make the data that already exists available to bring on the server

Update - Tried the below XSLT transformation to debug the structure and extract the Year information

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text" encoding="UTF-8" />

    <xsl:template match="/">
        <xsl:choose>
            <xsl:when test="ReportA">
                <xsl:text>Found ReportA element.&#10;</xsl:text>
  
                <xsl:choose>
                    <xsl:when test="ReportA/Year">
                        <xsl:text>Found Year element as a direct child of ReportA.&#10;</xsl:text>
                        <xsl:value-of select="ReportA/Year"/>
                    </xsl:when>
                    <xsl:otherwise>
                        
                        <xsl:text>No Year element found as a direct child of ReportA.&#10;</xsl:text>
                        <error>No Year element found as a direct child of ReportA</error>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>No ReportA element found.&#10;</xsl:text>
                <error>No ReportA element found</error>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
0

There are 0 best solutions below