問(wèn)題描述
出于某種原因,當(dāng)我查詢 XML 字段時(shí),Visual Studio 沒(méi)有向我顯示特殊字符.也許我存儲(chǔ)錯(cuò)誤?這些是明智的報(bào)價(jià)
For some reason Visual Studio does not show me special characters when I query for an XML field. Maybe I stored them wrong? These are smart quotes
這是查詢:
select CustomFields from TABLE where ID=422567 FOR XML PATH('')
當(dāng)我復(fù)制/粘貼到記事本++時(shí),我看到:
When I copy/paste into notepad++ I see this:
什么是 STS 和 CCH?
What are STS and CCH?
推薦答案
字符串 - 正如您肯定知道的 - 只是數(shù)字鏈.它們的含義和解釋方式取決于代碼頁(yè)、編碼、小端或大端...
Strings are - as you surely know - just chains of numbers. What they mean and how they are interpreted is depending on codepages, encodings, little or big endian ...
看看這個(gè)
SELECT 'test' AS NormalText
--non printable characters
--they are things like backspace, carriage return
,CHAR(0x6) AS ACK --DEC 7
,CHAR(0x7) AS BEL --DEC 9
,CHAR(0x1A) AS CR --DEC 13
,CHAR(0x1B) AS ESC --DEC 27
--printable characters from 0x21 (DEC 33) up to 0x7F (DEC 127) - (almost) not depending on encoding
,CHAR(0x41) AS BigA --DEC 65
,CHAR(0x7E) AS Tilde --DEC 126
--extended - from 0x80 (DEC 128) - very much depending on encoding!
,CHAR(0x93) AS STS --DEC 147
,CHAR(0x94) AS CCH --DEC 148
,CHAR(0x93) + 'test' + CHAR(0x94) AS Mixed
FOR XML PATH('')
這將產(chǎn)生這個(gè)
<NormalText>test</NormalText>
<ACK></ACK>
<BEL></BEL>
<CR></CR>
<ESC></ESC>
<BigA>A</BigA>
<Tilde>~</Tilde>
<STS>"</STS>
<CCH>"</CCH>
<Mixed>"test"</Mixed>
如您所見(jiàn),有些字符必須編碼,因?yàn)樗鼈儧](méi)有字符表達(dá),其他的則顯示相應(yīng)的圖片".
As you see, there are characters which must be encoded, as there is no character expression for them, others are displayed with their corresponding "picture".
如果代碼高于 DEC 127,您將進(jìn)入危險(xiǎn)地帶.相同的字符串可能會(huì)產(chǎn)生完全不同的輸出,具體取決于您閱讀的位置.
With codes above DEC 127 you enter dangerous terrain. The same string can produce quite different output depending on where you read it.
向您展示的STS"和CCH"記事本取自 C1 控制和 Latin-1 補(bǔ)充.
The "STS" and "CCH" Notepad shows to you, are taken from C1 Controls and Latin-1 Supplement.
This 和您示例中的書(shū)面 Smart qoutes 指向 this一>.為了允許smart qoutes,start 和end 的通用字符被替換"為合適的打開(kāi)和關(guān)閉qoutation 標(biāo)記.
This, and the written Smart qoutes in your example point to this. In order to allow smart qoutes there are general characters for start and end which are "replaced" with the fitting opening and closing qoutation marks.
最后,SQL Server 中的 XML 始終是 UTF16.看看這個(gè) feff0093 和 feff0094.這些是 UTF16 綁定到 0x93
和 0x94
的標(biāo)志.我的小例子清楚地表明了這一點(diǎn)......
Finally XML in SQL Server is always UTF16. Have a look at this feff0093 and feff0094. These are the signs UTF16 binds to 0x93
and 0x94
. My small example shows this clearly...
那么問(wèn)題是:為什么你的圖片沒(méi)有顯示和
"
?
So the question is: Why does your picture not show the "
and the "
?
我不知道...您放在第一行的 select
不會(huì)生成"這個(gè) XML,而是從CustomFields"列中取出現(xiàn)有的 XML.我相當(dāng)確定,這不是真正的"XML 列...
I don't know... The select
you put in the first line would not "produce" this XML, it rather takes existing XML out of a column "CustomFields". I'm fairly sure, that this is not a "real" XML-column...
這篇關(guān)于sql studio 看不到 XML 中的特殊字符的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!