首先把报错内容写一下:
Warning:  DOMDocument::loadXML() [<a href='domdocument.loadxml'>domdocument.loadxml</a>]: Input is not proper UTF-8, indicate encoding !
Bytes: 0xD2 0xD4 0xCD 0xF9 in Entity, line: 2 in <b>E:\web\code\lab2\standard.php</b> on line下面是standard.php的内容
<?php 
  $xml = new DomDocument();
  $xsl = new DomDocument();
  include 'mk_connnn.php';
  $xsl->load('connnn.xsl');
 
  $xml->loadXML($xml->saveXML());//这是第七行
  $proc = new XsltProcessor();
  $xsl =$proc->importStylesheet($xsl);
  $newdom =$proc->transformToDoc($xml);
  echo $newdom->saveXML();
// $str=mb_convert_encoding( $proc->transformToXML($xml),"GBK");
/* $str=preg_replace("/(<\?xml version=\"1.0\"\?>(\n)?| xmlns(:msxsl)?=\".[^\"]*\")/is","",$str);*/ //echo $str;?>下面是mk_connnn.php的内容
<?php
include_once('connnn.php');
$xml = new DomDocument('1.0','utf-8');
$xml->xmlStandalone =false;
$root = $xml -> createElement('entries');
$root = $xml -> appendChild($root);
if(isset($catID)){   //if catID is set
$sqlCat ='SELECT * FROM classfication WHERE catID ='.$catID;
$tresCat=mysql_query($sqlCat) or die(mysql_error("query error in cat"));
$rowCat =mysql_fetch_array($tresCat);
$catname =$rowCat['catname'];
$sql ='SELECT * FROM lab  WHERE catID ='.$catID ;
$cres = mysql_query($sql) or die(mysql_error());
$current = $xml ->createElement('current',$catname);
$current ->setAttribute('type','catname');$current ->setAttribute('id',mb_convert_encoding($catname,"UTF-8","GBK"));//看这一行
$root ->appendChild($current);
$items = $xml -> createElement('items');
$root ->appendChild($items);
$linksto = $xml -> createElement('linksto','city');
$items -> appendChild($linksto);
while($crow =mysql_fetch_array($cres)){$entry = $xml -> createElement('entry',$crow['proname']);
$entry ->setAttribute('id',mb_convert_encoding($crow['proID'],"UTF-8","GBK"));//注意看这一行
$items->appendChild($entry);
$bb = $xml -> createElement('br');
$items->appendChild($bb);}}
else{
$sqlLab = 'SELECT * FROM lab WHERE catID = 1';
$tresLab = mysql_query($sqlLab) or die(mysql_error());
$rowLab = mysql_fetch_array($tresLab);
$current = $xml ->createElement('current',$proname);
$current ->setAttribute('type','proname');
$current ->setAttribute('id',$proname);
$root ->appendChild($current);
$items = $xml ->createElement('items');
$root -> appendChild($items);
$entry = $xml -> createElement('entry',$rowLab['description']);
$entry -> setAttribute('id',$rowLab['proID']);
$items -> appendChild($entry);
}?>至于connnn.php,是涉及到数据库连接的,就不贴出了,现在的问题是,我的数据库的内容都是用utf8校对的,在connnn.php中,我加入了mysql_query("SET NAMES GBK");,为了防止从数据库中提取中文时出现乱码,然后,在mk_connnn.php中我要大家注意的两行,是由于提示非utf8编码而加入的,为了防止提示错误,但是程序运行后还是会出错(没有把index.php得代码贴出来,里面只有<?php include_once 'standard.php';?>这么一句,)。我也曾经把所有的都设为utf8编码,connnn.php中也没有设为GBK,然后我试图在standard.php中使用iconv解决这个问题,但是输出汉字仍为乱码,而且还是有报错,很郁闷。真的麻烦大家了,我在网上查了三天,试了好几种方案,都不管用,期待大家啊。