我从XMLWriter生成的XML文件中收到编码错误。但是我确信我可以通过将数据从当前的任何编码转换为UTF-8编码来解决此错误。
如果你能告诉我怎么做,我会很高兴。
错误是
This page contains the following errors:
error on line 2 at column 721: Encoding error
Below is a rendering of the page up to the first error.
第721行第2行的代码为<street>Mall CafÈ</street>
。
我的代码是:
$xml = new XMLWriter();
$xml->openURI("stores.xml");
$xml->startDocument("1.0");
$xml->startElement("stores");
while ($row = mysql_fetch_assoc($res)) {
$xml->startElement("store");
$xml->startElement("type");
$xml->writeRaw($row['type']);
$xml->endElement();
$xml->startElement("name");
$xml->writeRaw($row['name']);
$xml->endElement();
$xml->startElement("street");
$xml->writeRaw($row['street']);
$xml->endElement();
$xml->startElement("address1");
$xml->writeRaw($row['address1']);
$xml->endElement();
$xml->startElement("address2");
$xml->writeRaw($row['address2']);
$xml->endElement();
$xml->startElement("county");
$xml->writeRaw($row['county']);
$xml->endElement();
$xml->startElement("postcode");
$xml->writeRaw($row['postcode']);
$xml->endElement();
$xml->startElement("number");
$xml->writeRaw($row['number']);
$xml->endElement();
$xml->startElement("latlong");
$xml->writeRaw($row['latlong']);
$xml->endElement();
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
header ("Content-Type: text/xml");
$xml->flush();
?>
答案 0 :(得分:0)
$writer->startDocument("1.0", "UTF-8");