我使用个xsl文件将一个XML文件转换成html ,但是生成的html文件有两个<meta>标记,不知道是什么原因导致的。
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html">
<META http-equiv="Content-Type" content="text/html; charset=gb18030">
<LINK REL="stylesheet" HREF="print.css" type="text/css">
</HEAD>
<body>
...
</body>
这导致生成的html文件显示乱码,我必须去掉第一个<meta>,<META http-equiv="Content-Type" content="text/html">去掉它才能正常显示。
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html">
<META http-equiv="Content-Type" content="text/html; charset=gb18030">
<LINK REL="stylesheet" HREF="print.css" type="text/css">
</HEAD>
<body>
...
</body>
这导致生成的html文件显示乱码,我必须去掉第一个<meta>,<META http-equiv="Content-Type" content="text/html">去掉它才能正常显示。
BSTR abc = pXMLDoc->transformNode(pXSLDoc);
然后将abc写入一个html文件
XSL文件的开头的内容是:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" version="1.0" encoding="UTF-16" indent="yes"/>
<xsl:template match="/">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb18030"/>
<LINK REL="stylesheet" HREF="print.css" type="text/css"/>
</HEAD>
修改为
<META http-equiv="Content-Type" content="text/html; charset=gb18030"></META>试试。
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=erxPE33XEHA.3512%40TK2MSFTNGP12.phx.gblhttp://www.geocities.com/pmpg98_pt/CharacterEncoding.html
由显示乱码乱码到显示正常主要原因是我用记事本打开过这个文件然后保存了,我发现只要是用记事本打,不修改任何内容,开然后保存,这样也可以正常显示。
BSTR abc = pXMLDoc->transformNode(pXSLDoc); 我把这个转换后的BSTR直接写到了文件里,有什么问题吗,为什么会出现这种情况。