0
我明白XMLNAMESPACES
子句的主要目的是声明命名空间并进一步使用它。如何不显示XMLNAMESPACES别名
我有以下代码
DECLARE @XMLFINAL VARCHAR(MAX)
SET @XMLFINAL=''
DECLARE @NUMBER NVARCHAR(100)
DECLARE @XML VARCHAR(MAX)
DECLARE Records CURSOR FAST_FORWARD FOR
SELECT TOP 1 GID FROM PurchasesDocumentsLines
OPEN Records
FETCH NEXT FROM Records INTO @NUMBER
WHILE @@FETCH_STATUS = 0
BEGIN
SET @XML=''
;WITH XMLNAMESPACES ('OrderedProductSection' as q17)
SELECT @XML= (
SELECT
ProductCode as 'q17:ProductCode', OrderedQuantity 'q17:OrderedQuantity'
FROM PurchasesDocumentsLines WHERE [email protected]
FOR
XML RAW('q17:OrderedProductSection'), ELEMENTS
)
产生以下输出
<q17:OrderedProducts xmlns:q17="http://ITrack.Transmission/2011/02/25/Objects">
<q17:OrderedProductSection xmlns:q17="OrderedProductSection">
<q17:ProductCode>19A0010000</q17:ProductCode>
<q17:OrderedQuantity>2</q17:OrderedQuantity>
</q17:OrderedProductSection>
<q17:OrderedProductSection xmlns:q17="OrderedProductSection">
<q17:ProductCode>1G5Y010000</q17:ProductCode>
<q17:OrderedQuantity>3</q17:OrderedQuantity>
</q17:OrderedProductSection>
<q17:OrderedProductSection xmlns:q17="OrderedProductSection">
<q17:ProductCode>1G5Y020000</q17:ProductCode>
<q17:OrderedQuantity>4</q17:OrderedQuantity>
</q17:OrderedProductSection>
<q17:OrderedProductSection xmlns:q17="OrderedProductSection">
<q17:ProductCode>1G5Y030000</q17:ProductCode>
<q17:OrderedQuantity>5</q17:OrderedQuantity>
</q17:OrderedProductSection>
<q17:OrderedProductSection xmlns:q17="OrderedProductSection">
<q17:ProductCode>1G5Y040000</q17:ProductCode>
<q17:OrderedQuantity>6</q17:OrderedQuantity>
</q17:OrderedProductSection>
</q17:OrderedProducts>
而现在,愚蠢的问题,希望能够找到一个解决方案:有没有什么办法,对于<q17:OrderedProductSection xmlns:q17="OrderedProductSection">
标签,不显示xmlns:q17="OrderedProductSection"
?因为拥有一个空的URI是不允许的。由于
LE
与REPLACE
功能实现它。
编辑
<q17:OrderedProducts xmlns:q17="http://ITrack.Transmission/2011/02/25/Objects">
<q17:ProductCode>19A0010000</q17:ProductCode>
<q17:OrderedQuantity>2</q17:OrderedQuantity>
<q17:ProductCode>1G5Y010000</q17:ProductCode>
<q17:OrderedQuantity>3</q17:OrderedQuantity>
</q17:OrderedProducts>
有什么办法避免'root',使代码看起来像我的编辑?谢谢 – cdrrrrr
@cdrrrrr哪里有? –
Shnugo
@cdrrrrr如果你确实需要它,那很容易(但我不会建议这个结构!)。只需将最后一行代码替换为FOR XML PATH(''),ROOT('q17:OrderedProducts');'。空的'PATH('')'将返回,没有行包装节点 – Shnugo