Php mySQL输出到XML错误

Php mySQL输出到XML错误,php,mysql,xml,Php,Mysql,Xml,如果API键正确,我想用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 = "SELE

如果API键正确,我想用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,只需使用row值作为startElement的第二个参数即可

$xml->startElement("Player",$row['Player']);
别忘了关闭文档

$xml->endDocument();   
以前

$xml->flush();

您希望如何显示您的玩家值?作为玩家标签的单独值或属性值?例如:Codeek Germany Hi它不起作用,但我做了一些更改(例如从fetch_assoc中删除$con,但现在它只显示数据库中的所有名称,没有XML结构。知道怎么了吗?我会更新我的新代码。Nvm忘了单击“Show source code command”,谢谢:)。很高兴听到你找到了解决方案。答案是thnx,但如果没有帮助你,你就不应该这么做:),nvm。编码愉快