国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

包含中文字符的URL編碼問(wèn)題

2019-11-18 20:01:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

xml應(yīng)用中,經(jīng)常將一些URL信息作為xml數(shù)據(jù)存儲(chǔ),其中URL參數(shù)有可能包含有中文字符。當(dāng)使用dom對(duì)xml數(shù)據(jù)進(jìn)行解析時(shí),可以對(duì)中文字符進(jìn)行編碼。
但如果只使用xslt來(lái)顯示xml數(shù)據(jù)時(shí)(data.xml+data.xsl),發(fā)現(xiàn)此時(shí)的URL會(huì)出現(xiàn)編碼錯(cuò)誤.即使指定編碼類型(encoding="gb2312"),依然會(huì)出現(xiàn)同樣的問(wèn)題.
測(cè)試發(fā)現(xiàn):是IE的緩存機(jī)制問(wèn)題,IE仍會(huì)把新的頁(yè)面(所鏈接的URL)的MIME內(nèi)容類型默認(rèn)為text/xml

解決方法:
1.指定輸出文檔類型為xml文檔  (example:data.xsl)
 <xsl:output method="xml"  encoding="gb2312" media-type="text/xml" />
2.在新的窗口打開(kāi),給聯(lián)接增加屬性,指明目標(biāo)窗口為其他窗口  (example:data2.xsl)
 <xsl:attribute name="target">_blank</xsl:attribute>


examples:


/*** data.xml ***/

<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<root>
 <search>
  <url>http://www.google.com/search?q=</url>
  <Word>xml數(shù)據(jù)</word>
 </search>
 <search>
  <url>http://www1.baidu.com/baidu?word=</url>
  <word>xml數(shù)據(jù)</word>
 </search>
 <search>
  <url>http://www.google.com/search?q=</url>
  <word>極限編程(xp)</word>
 </search>
 <search>
  <url>http://www1.baidu.com/baidu?word=</url>
  <word>極限編程(xp)</word>
 </search>
</root>


/*** data.xsl ***/

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="<!-- 去掉下面一句,將出現(xiàn)錯(cuò)誤 -->
<xsl:output method="xml"  encoding="gb2312" media-type="text/xml" />

<xsl:template match="/">
 <xsl:apply-templates /> 
</xsl:template>

<xsl:template match="search">
 <xsl:element name="a">
  <xsl:attribute name="href"><xsl:value-of select="url" /><xsl:value-of select="word" /></xsl:attribute>
  <xsl:value-of select="word" />
 </xsl:element>
 <br />
</xsl:template>

</xsl:stylesheet>


/*** data2.xsl ***/

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="

<xsl:template match="/">
 <xsl:apply-templates /> 
</xsl:template>

<xsl:template match="search">
 <xsl:element name="a">
  <xsl:attribute name="href"><xsl:value-of select="url" /><xsl:value-of select="word" /></xsl:attribute>
  <!-- 去掉下面一句,將出現(xiàn)錯(cuò)誤 -->
  <xsl:attribute name="target">_blank</xsl:attribute>
  <xsl:value-of select="word" />
 </xsl:element>
 <br />
</xsl:template>

</xsl:stylesheet>



發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜宾县| 新干县| 东山县| 若尔盖县| 祁门县| 治县。| 晴隆县| 兴安县| 崇明县| 科尔| 雷州市| 寻乌县| 修文县| 皮山县| 青冈县| 孝感市| 商河县| 岗巴县| 绥中县| 临澧县| 阳山县| 汤阴县| 周口市| 万全县| 平度市| 家居| 若羌县| 望谟县| 浙江省| 潜山县| 陈巴尔虎旗| 德兴市| 长子县| 钦州市| 马公市| 高密市| 平度市| 望城县| 岳阳县| 上林县| 济南市|