如果 API key 正确,我想以 XML 形式显示我的数据库。 一切正常,直到 XML 页面出现。 它显示此错误:
This page contains the following errors:
error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
我的代码:
$sql = "SELECT * FROM WKplayers";
$res = mysqli_query($con, $sql);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('Players');
while ($row = mysqli_fetch_assoc($res)) {
$xml->startElement("Player");
$xml->startElement("Name");
$xml->writeRaw($row['Player']);
$xml->endElement();
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->endDocument();
$xml->flush();
最佳答案
我发现在您的上下文中没有必要使用 writeraw,只需使用行值作为 startElement 的第二个参数即可
$xml->startElement("Player",$row['Player']);
并且不要忘记通过
关闭文档$xml->endDocument();
之前
$xml->flush();
关于php - mySQL 输出到 XML 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27876845/