Home > Backend Development > XML/RSS Tutorial > Detailed analysis of URL encoding issues containing Chinese characters

Detailed analysis of URL encoding issues containing Chinese characters

黄舟
Release: 2017-03-06 16:40:51
Original
1711 people have browsed it

In xml applications, some URL information is often stored as xml data, and the URL parameters may contain Chinese characters. When using dom to parse xml data, Chinese characters can be encoded.
But if you only use xslt to display xml data (data.xml+data.xsl), you will find that the URL will have an encoding error. Even if you specify the encoding type (encoding="gb2312"), the same error will still occur. Problem.
The test found that it is a problem with IE’s caching mechanism. IE will still default the MIME content type of the new page (linked URL) to text/xml

Solution:
1 .Specify the output document type as xml document (example:data.xsl)

<xsl:output method="xml"  encoding="gb2312" media-type="text/xml" />
Copy after login

2. Open in a new window, add attributes to the connection, and specify that the target window is another window (example:data2.xsl )

 _blank
examples:
/*** data.xml ***/



 
  http://www.google.com/search?q=
  xml数据
 
 
  http://www1.baidu.com/baidu?word=
  xml数据
 
 
  http://www.google.com/search?q=
  极限编程(xp)
 
 
  http://www1.baidu.com/baidu?word=
  极限编程(xp)
 


/*** data.xsl ***/



<xsl:output method="xml"  encoding="gb2312" media-type="text/xml" />

   


 
  
  
 
 
/*** data2.xsl ***/ _blank
Copy after login

The above is a detailed analysis of URL encoding issues containing Chinese characters. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
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