本文介紹了SQL XML 向根添加元素的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個通過 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">
我希望它看起來像這樣:
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
它返回第一個根,我如何讓它像我展示的第二個根一樣返回?
and it returns the first root, how do I get it return like the second root I showed?
推薦答案
您需要使用 WITH XMLNAMESPACES
試試這個:
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')
結果
<ArrayOfKeyValueOfstringPunchListCellModel84zsBx89 xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" />
這篇關于SQL XML 向根添加元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!