Home > Backend Development > XML/RSS Tutorial > Detailed introduction to the case of testing several xml problems

Detailed introduction to the case of testing several xml problems

黄舟
Release: 2017-03-22 16:30:42
Original
1997 people have browsed it

When using sql server, it is inevitable to deal with xml parameters. xml brings convenience to our programs most of the time, but there are also times when variable assignment fails. (Of course, if your own xml cannot pass the inspection of software such as xml spy, then this is not the scope of this aspect~)

The examples shared today are very simple, just test a few examples

DECLARE @x XML  
 
 
SELECT @x =
&#39;<a>1</a>&#39;
 
SELECT @x =
&#39;<?xml version="1.0" encoding="utf-8"?>
<a>1</a>
&#39;
 
SELECT @x =
N&#39;<?xml version="1.0" encoding="utf-8"?>
<a>1</a>
&#39;
 
SELECT @x =
&#39;<?xml version="1.0" encoding="utf-8"?>
<a>一个人</a>
&#39;
 
SELECT @x =
&#39;<?xml version="1.0" encoding="GBK"?>
<a>单身狗汪</a>
Copy after login

Example 1:

This is the most common example we see, and it can be compiled without any pressure. The variable assignment passed, and then the query, parsing, whatever you want~

Example 2:

The compilation also passed. It seems that this is the most likely place to cause misunderstandings. I always thought that sql server The assignment inside does not support headers like

<?xml version="1.0" encoding="utf-8"?>
Copy after login

, so I usually tell the coder that if such an error occurs, just remove the header (it will indeed work, but the reason is wrong (⊙ ﹏⊙)b). In fact, the XML type itself is supported, but it is just a matter of application scenarios when we call stored procedures or assign parameters in statements. sql server said that I will not bear this responsibility

Example 3:

There is a problem in compiling this example, and the compiler throws

Message 9402, level 16, status 1 , Line 8
XML analysis: Line 1, character 38, encoding cannot be switched

However, the difference between Example 3 and Example 2 is that the assignment in Example 3 uses unicode encoding, while Example 2 does not. Do it, so in Example 3, I fell to my knees instantly ╮(╯_╰)╭. Therefore, the database parameter transfer errors we usually find are because this method is used, so I have been fooled_(:з」∠)_. So it’s not that it’s not supported, it’s just that there’s a problem with our calling method

Example 4:

Message 9420, level 16, status 1, line 9
XML analysis: line 2, character 5. Illegal xml characters

Hey~ Another error is reported~ This time it is an illegal xml character. It seems that the encoding is utf-8, which does not support Chinese. So sometimes if you don’t pay attention to these details, it’s really.../(ㄒoㄒ)/~~

Example 5:

The compilation passed successfully, this time the encoding inside was changed to GBK encoding, It can support Chinese. Of course, compilation is no problem at all.

To add another example

SELECT @x =
&#39;<?xml version="1.0" encoding="GBK"?>
<a>繁体字 龍 _(:з」∠)_</a>
Copy after login

is also ok. Some traditional Chinese characters are also supported in the GBK font library, and generally there is no need to worry about this issue. Unless there are some special symbols, it’s hard to say haha

Finally, encoding="utf-8" and encoding="UTF-8" are equivalent, and there is no case sensitivity here. Note that here...

The above is the detailed content of Detailed introduction to the case of testing several xml problems. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
xml
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template