如何在 SQL Server 2014 的 XML 根目录中添加 xmlns
问题描述
我正在尝试添加 xmlns MsgDtTm
&MessageId
SQL Server 2014 中 XML 根元素中的属性.我正在尝试:
I am trying to add xmlns MsgDtTm
& MessageId
attributes in root element of XML in SQL Server 2014. I am trying this:
得到这个结果
我在 Default
元素中获得了空白的 xmlns
属性.我希望 Person
元素中的 xmlns
不在 Default
元素中.我的预期结果如下:
I am getting the blank xmlns
attribute in Default
element. I want xmlns
in Person
element not in Default
element. My expected result is as follows:
如果我使用 ;WITH XMLNAMESPACES ('http://abc.go.com' as f)
那么它将在 root 中,但结果我会得到 xmlns:f=..."
.我不想附加 :objectOfXMLNAMESPACES
,我只想要 xmlns.
if I use ;WITH XMLNAMESPACES ('http://abc.go.com' as f)
then it will be in root but in result I will get xmlns:f="..."
. I don't want to append :objectOfXMLNAMESPACES
, I just want xmlns.
推荐答案
SQL Server 一遍又一遍地为每个子选择添加命名空间,这是一个非常烦人的行为.
It is a very annoying behaviour, that SQL Server adds namespaces to each sub-select over and over.
您会在 SO 上找到很多解决方法,有些使用丑陋的 NVARCHAR(MAX)
强制转换以在字符串基础上插入命名空间,其他使用或多或少复杂的方式.
You will find a lot of workarounds here on SO, some use an ugly cast to NVARCHAR(MAX)
to insert the namespace on string base, other use more or less complicated ways.
对你来说最简单的应该是这样的:
For you the simplest should be this:
重要
请点击此链接,登录并投票.
这是一个持续年的众所周知的问题!..
这篇关于如何在 SQL Server 2014 的 XML 根目录中添加 xmlns的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!