国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 绿春县| 沅江市| 房产| 府谷县| 麦盖提县| 原阳县| 偏关县| 金平| 晋宁县| 左云县| 伊金霍洛旗| 白城市| 永济市| 阜南县| 新宾| 毕节市| 乌兰浩特市| 东至县| 巨鹿县| 凤冈县| 塔河县| 西宁市| 松原市| 吴旗县| 武平县| 府谷县| 皮山县| 微博| SHOW| 肇庆市| 仁寿县| 和平县| 楚雄市| 浦东新区| 清水河县| 云浮市| 巴东县| 安岳县| 武胜县| 福安市| 洞头县|