本文介紹了SQL XML 向根添加元素的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有一個(gè)通過(guò) SQL 生成的 XML,根如下所示:
I have an XML that is being generated via SQL and the root looks like this:
<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89
ns1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
我希望它看起來(lái)像這樣:
I want it to look like so:
<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
這是我的 SQL 代碼:
Here is my SQL code:
DECLARE @persons XML = (
SELECT(
blah blah blah
)FOR XML PATH(''), ROOT('ArrayOfKeyValueOfstringPunchListCellModel84zsBx89'))
set @persons.modify('insert ( attribute ns1 {"http://schemas.microsoft.com/2003/10/Serialization/Arrays"}) into (/ArrayOfKeyValueOfstringPunchListCellModel84zsBx89)[1]')
SELECT @persons
它返回第一個(gè)根,我如何讓它像我展示的第二個(gè)根一樣返回?
and it returns the first root, how do I get it return like the second root I showed?
推薦答案
您需要使用 WITH XMLNAMESPACES
試試這個(gè):
WITH XMLNAMESPACES('http://www.w3.org/2001/XMLSchema-instance' AS i
,DEFAULT 'http://schemas.microsoft.com/2003/10/Serialization/Arrays')
SELECT NULL
FOR XML PATH('ArrayOfKeyValueOfstringPunchListCellModel84zsBx89')
結(jié)果
<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89 xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" />
這篇關(guān)于SQL XML 向根添加元素的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!