我正在尝试插入版本&命名空间信息到我在sql 2005查询中创建的xml文档。
我已经尝试声明一个xml变量并为其分配文字。不确定我是否必须使用命名空间或可以执行以下操作:
DECLARE @doc2 XML;
SET @doc2 =N'<ActionChangeRequest
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.customersite.com/xmlapi">
</ActionRequest>'
SELECT @doc2,
+
SELECT
( SELECT .....
FROM tbl A1
FOR XML PATH('Customer'), TYPE ),
( SELECT ......
FROM tbl A2
FOR XML PATH('RepairFacility'), TYPE),
( SELECT .....
FROM tbl J
FOR XML PATH('Action'), TYPE )
FOR XML PATH(''), ROOT('Element')
答案 0 :(得分:0)
我不确定您希望XML看起来如何,但使用WITH XMLNAMESPACES查询将如下所示:
;with xmlnamespaces( default 'http://www.customersite.com/xmlapi',
'http://www.w3.org/2001/XMLSchema' as xsd,
'http://www.w3.org/2001/XMLSchema-instance' as xsi
)
select '' as '*'
for xml path(''), root('ActionRequest')
结果:
<ActionRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.customersite.com/xmlapi"></ActionRequest>