与以下
DECLARE @t TABLE (Test nvarchar(50), Location_ID uniqueidentifier);
INSERT INTO @t (Test,Location_ID )
SELECT Test,Location_ID
from
dbo.TEST;
DECLARE @xml XML
;WITH XMLNAMESPACES (
'typens:GPCodedValueDomain2' as type,
'http://www.esri.com/schemas/ArcGIS/10.0' as typens,
'http://www.w3.org/TR/html4/' AS xs,
'http://www.w3.org/2001/XMLSchema-instance' AS xsi )
SELECT @xml =
(
SELECT
'typens:CodedValue' AS "@xsi:type",
TEST AS "Name", Location_ID AS "Code"
FROM @t
order by Location_ID
FOR XML PATH
('CodedValue'), ROOT
('GPCodedValueDomain2'),TYPE
)
SELECT @xml
它输出
<GPCodedValueDomain2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/TR/html4/" xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.0" xmlns:type="typens:GPCodedValueDomain2">
<CodedValue xsi:type="typens:CodedValue">
<Name>test update</Name>
<Code>B59D3BEB-CBCE-E111-B5B0-002564D275D1</Code>
</CodedValue>
<CodedValue xsi:type="typens:CodedValue">
<Name>test update</Name>
<Code>B69D3BEB-CBCE-E111-B5B0-002564D275D1</Code>
</CodedValue>
<CodedValue xsi:type="typens:CodedValue">
<Name>test update</Name>
<Code>B79D3BEB-CBCE-E111-B5B0-002564D275D1</Code>
</CodedValue>
</GPCodedValueDomain2>
几个小时以来,我一直在尝试不同的命名空间定义迭代,但都失败了。我正在寻找的输出是:
<GPCodedValueDomain2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/TR/html4/" xmlns:typens="http://www.esri.com/schemas/ArcGIS/10.0" xmlns:type="typens:GPCodedValueDomain2">
<CodedValue xsi:type="typens:CodedValue">
<Name>test update</Name>
<Code xsi:type="xs:string">B59D3BEB-CBCE-E111-B5B0-002564D275D1</Code>
</CodedValue>
<CodedValue xsi:type="typens:CodedValue">
<Name>test update</Name>
<Code xsi:type="xs:string">B69D3BEB-CBCE-E111-B5B0-002564D275D1</Code>
</CodedValue>
<CodedValue xsi:type="typens:CodedValue">
<Name>test update</Name>
<Code xsi:type="xs:string">B79D3BEB-CBCE-E111-B5B0-002564D275D1</Code>
</CodedValue>
</GPCodedValueDomain2>
关于如何实现这一点的任何想法?谢谢