You can output xml directly from MSSQL without using SSIS, you would use the column aliases to set your custom tags/attributes.
Please see below demonstration, attributes are aliased with a @ prefix and tags without any prefix, sub tags are built with /
Multiline sub tags are built with a subquery
IF OBJECT_ID('tempdb.dbo.#StackOverflowTestParent') IS NOT NULL DROP TABLE #StackOverflowTestParent
CREATE TABLE #StackOverflowTestParent
(
ParentId BIGINT PRIMARY KEY IDENTITY(1,1),
ParentAttribute1 VARCHAR(50),
ParentAttribute2 VARCHAR(50),
ParentValue VARCHAR(50)
)
INSERT INTO #StackOverflowTestParent VALUES ('Oh','Hello','World')
INSERT INTO #StackOverflowTestParent VALUES ('World','Goes','Hello')
IF OBJECT_ID('tempdb.dbo.#StackOverflowTestParent') IS NOT NULL DROP TABLE #StackOverflowTestParent
CREATE TABLE #StackOverflowTestChild
(
ChildId BIGINT PRIMARY KEY IDENTITY(1,1),
ParentId BIGINT,
ChildAttribute1 VARCHAR(50),
ChildAttribute2 VARCHAR(50),
ChildValue VARCHAR(50)
)
INSERT INTO #StackOverflowTestChild VALUES (1,'Bobby','Says','Hello')
INSERT INTO #StackOverflowTestChild VALUES (1,'Dobby','Starts','Waving')
INSERT INTO #StackOverflowTestChild VALUES (2,'Dolly','Says','Hozit')
INSERT INTO #StackOverflowTestChild VALUES (2,'Sarah','Says','Hi')
IF OBJECT_ID('tempdb.dbo.#StackOverflowTestParent') IS NOT NULL DROP TABLE #StackOverflowTestParent
CREATE TABLE #StackOverflowTestParent
(
ParentId BIGINT PRIMARY KEY IDENTITY(1,1),
ParentAttribute1 VARCHAR(50),
ParentAttribute2 VARCHAR(50),
ParentValue VARCHAR(50)
)
INSERT INTO #StackOverflowTestParent VALUES ('Oh','Hello','World')
INSERT INTO #StackOverflowTestParent VALUES ('World','Goes','Hello')
IF OBJECT_ID('tempdb.dbo.#StackOverflowTestParent') IS NOT NULL DROP TABLE #StackOverflowTestParent
CREATE TABLE #StackOverflowTestChild
(
ChildId BIGINT PRIMARY KEY IDENTITY(1,1),
ParentId BIGINT,
ChildAttribute1 VARCHAR(50),
ChildAttribute2 VARCHAR(50),
ChildValue VARCHAR(50)
)
INSERT INTO #StackOverflowTestChild VALUES (1,'Bobby','Says','Hello')
INSERT INTO #StackOverflowTestChild VALUES (1,'Dobby','Starts','Waving')
INSERT INTO #StackOverflowTestChild VALUES (2,'Dolly','Says','Hozit')
INSERT INTO #StackOverflowTestChild VALUES (2,'Sarah','Says','Hi')
;WITH XMLNAMESPACES ( 'www.example.com' AS ns0)
SELECT P.ParentId AS '@ParentId',
P.ParentAttribute1 AS '@CustomAttribute1',
P.ParentAttribute2 AS 'ParentSub/@CustomAttribute2',
P.ParentValue AS 'StackOverflowTestMessage',
/* Building child node with a subquery*/
(SELECT C.ChildId AS '@ChildUniqueId',
C.ChildAttribute1 AS '@ChildAttribute1',
C.ChildAttribute2 AS 'SubChildSingle/@ChildAttribute2',
C.ChildValue AS 'StackOverflowTestChild'
FROM #StackOverflowTestChild C
WHERE C.ParentId = P.ParentId
FOR XML PATH('CustomChildNode'),TYPE)
FROM #StackOverflowTestParent P
FOR XML PATH('StackOverflowTestParent'),ROOT('ns0:Root')
Result
<ns0:Root xmlns:ns0="www.example.com">
<StackOverflowTestParent ParentId="1"
CustomAttribute1="Oh">
<ParentSub CustomAttribute2="Hello" />
<StackOverflowTestMessage>World</StackOverflowTestMessage>
<CustomChildNode xmlns:ns0="www.example.com"
ChildUniqueId="1"
ChildAttribute1="Bobby">
<SubChildSingle ChildAttribute2="Says" />
<StackOverflowTestChild>Hello</StackOverflowTestChild>
</CustomChildNode>
<CustomChildNode xmlns:ns0="www.example.com"
ChildUniqueId="2"
ChildAttribute1="Dobby">
<SubChildSingle ChildAttribute2="Starts" />
<StackOverflowTestChild>Waving</StackOverflowTestChild>
</CustomChildNode>
</StackOverflowTestParent>
<StackOverflowTestParent ParentId="2"
CustomAttribute1="World">
<ParentSub CustomAttribute2="Goes" />
<StackOverflowTestMessage>Hello</StackOverflowTestMessage>
<CustomChildNode xmlns:ns0="www.example.com"
ChildUniqueId="3"
ChildAttribute1="Dolly">
<SubChildSingle ChildAttribute2="Says" />
<StackOverflowTestChild>Hozit</StackOverflowTestChild>
</CustomChildNode>
<CustomChildNode xmlns:ns0="www.example.com"
ChildUniqueId="4"
ChildAttribute1="Sarah">
<SubChildSingle ChildAttribute2="Says" />
<StackOverflowTestChild>Hi</StackOverflowTestChild>
</CustomChildNode>
</StackOverflowTestParent>
</ns0:Root>
Edit
Here is another example of how create a basic version with both namespaces
/* Here is a more basic version */
;WITH XMLNAMESPACES ( 'www.example.com' AS ns0, 'w3/XMLSchema-instance' AS xsi)
SELECT P.ParentAttribute1 AS 'ColumnNames/ParentAttribute1',
P.ParentAttribute2 AS 'ColumnNames/ParentAttribute2',
P.ParentValue AS 'ColumnNames/ParentValue'
FROM #StackOverflowTestParent P
FOR XML PATH('CustomTag'),ROOT('ns0:Root')
Result
<ns0:Root xmlns:xsi="w3/XMLSchema-instance" xmlns:ns0="www.example.com">
<CustomTag>
<ColumnNames>
<ParentAttribute1>Oh</ParentAttribute1>
<ParentAttribute2>Hello</ParentAttribute2>
<ParentValue>World</ParentValue>
</ColumnNames>
</CustomTag>
<CustomTag>
<ColumnNames>
<ParentAttribute1>World</ParentAttribute1>
<ParentAttribute2>Goes</ParentAttribute2>
<ParentValue>Hello</ParentValue>
</ColumnNames>
</CustomTag>
</ns0:Root>