次の形式でXMLを構築しようとしています(プロバイダーにはXSDがありません)。
<Submission>
<Office Account="ACCOUNT">
<schedule submissionPeriod="" areaOfLaw="" scheduleNum="abc">
<outcome matterType="A:B">
<outcomeItem Name="CASE_START_DATE">DATA</outcomeItem>
<outcomeItem Name="CASE_ID">DATA</outcomeItem>
</outcome>
<outcome matterType="C:D">
<outcomeItem Name="CASE_START_DATE">DATA</outcomeItem>
<outcomeItem Name="CASE_ID">DATA</outcomeItem>
</outcome>
</schedule>
<schedule submissionPeriod="" areaOfLaw="" scheduleNum="def">
<outcome matterType="E:F">
<outcomeItem Name="CASE_START_DATE">DATA</outcomeItem>
<outcomeItem Name="CASE_ID">DATA</outcomeItem>
</outcome>
</schedule>
</Office>
<Office Account="ACCOUNT2">
<schedule submissionPeriod="" areaOfLaw="" scheduleNum="ghi">
<outcome matterType="A:B">
<outcomeItem Name="CASE_START_DATE">DATA</outcomeItem>
<outcomeItem Name="CASE_ID">DATA</outcomeItem>
</outcome>
</schedule>
</Office>
私は次のSQLを持っています
SELECT supplier_no AS 'Office/@Account' ,
UPPER(LEFT(DATENAME(MM, GETDATE()), 3)) + '-' + DATENAME(YYYY,
GETDATE()) AS 'Office/schedule/@submissionPeriod' ,
'LEGAL HELP' AS 'Office/schedule/@areaOfLaw' ,
supplier_no + '/CIVIL' AS 'Office/schedule/@scheduleNum' ,
ClaimsTable.mattype1_code + ':' + ClaimsTable.mattype2_code AS 'Office/schedule/outcome/@matterType' ,
(SELECT * FROM (
SELECT 'CASE_START_DATE' AS 'outcomeItem/@Name', 'DATA' AS 'outcomeItem' UNION ALL
SELECT 'CASE_ID' AS 'outcomeItem/@Name', 'DATA' AS 'outcomeItem'
) OutcomeItems FOR XML PATH(''), TYPE) AS 'Office/schedule/outcome'
FROM ContractsTable
LEFT OUTER JOIN ClaimsTable ON ContractsTable.contract_no = ClaimsTable.contract_no
WHERE ClaimsTable.compno = 2
AND ClaimsTable.submitted_period = 0
FOR XML PATH('Submission') ,
TYPE
次のXMLを生成しています
<Submission>
<Office Account="MHESUPPLIE">
<schedule submissionPeriod="FEB-2013" areaOfLaw="LEGAL HELP" scheduleNum="MHESUPPLIE/CIVIL">
<outcome matterType="MHNS:MOUT">
<outcomeItem Name="CASE_START_DATE">13/02/2013</outcomeItem>
<outcomeItem Name="CASE_ID">001</outcomeItem>
</outcome>
</schedule>
</Office>
</Submission>
<Submission>
<Office Account="MHESUPPLIE">
<schedule submissionPeriod="FEB-2013" areaOfLaw="LEGAL HELP" scheduleNum="MHESUPPLIE/CIVIL">
<outcome matterType="MHAS:MGUA">
<outcomeItem Name="CASE_START_DATE">14/02/2013</outcomeItem>
<outcomeItem Name="CASE_ID">001</outcomeItem>
</outcome>
</schedule>
</Office>
</Submission>
明らかに、出力XMLには無効な複数のルートノードがあります。結果を組み合わせて、必要なXMLタイプを実現する方法を見つけようとしています。SQL Server 2005+でこれを実現する方法について何かアイデアはありますか?