【发布时间】:2009-10-12 23:23:49
【问题描述】:
我正在尝试创建要存储在 SQL Server 2005 中的 XML 字段中的 Excel XML。我已经做到了这一点:
WITH XMLNAMESPACES (
'urn:schemas-microsoft-com:office:spreadsheet' as "s",
'urn:schemas-microsoft-com:office:office' as "o",
'urn:schemas-microsoft-com:office:excel' as "x"
)
select 'Order' as "@s:Name",
(
select
'String' as 's:Cell/s:Data/@s:Type',
[Order] as 's:Cell/s:Data',
null as 'tmp',
'String' as 's:Cell/s:Data/@s:Type',
[Material] as 's:Cell/s:Data',
null as 'tmp',
'String' as 's:Cell/s:Data/@s:Type',
[Ship-To] as 's:Cell/s:Data'
from
(
select
'Order' as [Order],
'Material' as [Material],
'Ship-To' as [Ship-To]
union all
select
[Order],
[Material],
[Ship-To]
from Orders
WHERE [Material] IN(1234,5678))
) as Temp
FOR XML PATH('s:Row'), type
) AS 's:Table'
FOR XML PATH('s:Worksheet'), root('s:Workbook')
这是我的输出:
<s:Workbook xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
<s:Worksheet s:Name="Order">
<s:Table>
<s:Row xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
<s:Cell>
<s:Data s:Type="String">Order</s:Data>
</s:Cell>
<s:Cell>
<s:Data s:Type="String">Material</s:Data>
</s:Cell>
<s:Cell>
<s:Data s:Type="String">Ship-To</s:Data>
</s:Cell>
</s:Row>
<s:Row xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
<s:Cell>
<s:Data s:Type="String">200909</s:Data>
</s:Cell>
<s:Cell>
<s:Data s:Type="String">1234</s:Data>
</s:Cell>
<s:Cell>
<s:Data s:Type="String">US</s:Data>
</s:Cell>
</s:Row>
<s:Row xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
<s:Cell>
<s:Data s:Type="String">200909</s:Data>
</s:Cell>
<s:Cell>
<s:Data s:Type="String">5678</s:Data>
</s:Cell>
<s:Cell>
<s:Data s:Type="String">ASIA</s:Data>
</s:Cell>
</s:Row>
</s:Table>
</s:Worksheet>
</s:Workbook>
我想要的是消除<s:Row> 节点中的命名空间。我想摆脱这个:xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet" from <s:Row xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:s="urn:schemas-microsoft-com:office:spreadsheet">
有人知道怎么做吗?
【问题讨论】:
-
为什么要消除它们?它们是多余的,但却是正确的。
-
我正在处理大量数据。虽然它现在可以正常工作,但如果我能修剪掉真正不必要的部分,那就太好了。
标签: sql xml sql-server-2005 for-xml