SSIS XML write file task - how to preserve empty values?

Naomi Nosonovsky 8,291 Reputation points
2025-03-10T21:32:16.3566667+00:00

Hi,

We have SSIS package that writes XMLs into files. We have stored procedure that generates XML and outputs it as XML with tags like this <MiddleName> </MiddleName>. In other words, there is a space (intentional) inside the tags. We have XML task in the package configured like this:

User's image

The problem is that resulting XML ends up being like this </MiddleName> and the space is gone. We need it to preserve spaces. Is there a way with the XML.write task or what should we do to write the XML the way we generated it in the stored procedure?

Thanks in advance.

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,664 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 119.3K Reputation points MVP
    2025-03-10T22:16:34.5666667+00:00

    That's how XML works, I guess. The same thing happens in SQL Server:

    DECLARE @x xml = '<Space> </Space>'
    SELECT @x
    

    This results in:

    <Space />

    If you want a space there, you to enticise it:

    DECLARE @x xml = '<Space>&#32;</Space>'
    SELECT @x
    

    This gives you:

    <Space> </Space>

    But then this will become <Space /> in the next round.

    I think a better solution is to use a hard space (char(160):

    DECLARE @x xml = '<Space>&#160;</Space>'
    SELECT @x
    

0 additional answers

Sort by: Most helpful

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.