在 SQL Server 2014 中,我尝试使用 XML 数据类型的“修改”方法添加一个带有属性(包含回车符)的 XML 元素。 回车被删除 - 这是为什么?
例子:
declare @xmldata xml
select
@xmldata = '<root><child myattr="carriage returns 
 are not a problem"></child></root>'
set
@xmldata.modify('insert <child>modifying text with carriage returns works
ok</child> after (//child)[1]')
set
@xmldata.modify('insert <child myattr="but not
attribute values... why is that?"></child> after (//child)[2]')
select @xmldata
结果:
<root>
<child myattr="carriage returns 
 are not a problem" />
<child>modifying text with carriage returns works
ok</child>
<child myattr="but not attribute values... why is that?" />
</root>
最佳答案
空白字符可以被解析器规范化。
比照http://www.w3.org/TR/1998/REC-xml-19980210#AVNormalize
虽然您的 XML 是有效的,但具体如何呈现空白取决于实现。如您所见,crlf 已替换为一个空格。
Please note
In general XML works different with Content and Structural/Meta Data
Attribute values are considered structure and data between tags is considered content.
In the design of XML it was never expected that attributes would be displayed on end-user devices, I would suggest you just make another tag for this end user content.
关于sql - 为什么在 SQL Server 中修改 XML 属性时会删除回车符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33829745/