我的 xml 中有错误(文档末尾的额外内容),我已经在整个互联网上进行了搜索,但没有任何解决方案有效。
我已经阅读了有关根目录或文档的内容,但并没有解决我的问题。
PHP:
<?php $doc = new DOMDocument('1.0', 'utf-8');
// we want a nice output
$doc->formatOutput = true;
$query = "SELECT * FROM leden";
while($q = mysql_fetch_assoc($query))
{
$user = $doc->createElement('user');
$user = $doc->appendChild($user);
$title = $doc->createElement('id');
$title = $user->appendChild($title);
$text = $doc->createTextNode($q['id']);
$text = $title->appendChild($text);
$title = $doc->createElement('nickname');
$title = $user->appendChild($title);
$text = $doc->createTextNode($q['gebruikersnaam']);
$text = $title->appendChild($text);
//etc.. etc
}
echo $doc->saveXML($doc);
?>
输出:
<?xml version="1.0" encoding="UTF-8"?>
<user>
<id>300</id>
<nickname>Peterjhonsen</nickname>
<url>http://www.abcd.nl/leden/peterjhons&refid=123&cp=gg</url>
<foto>http://www.abcd.nl/image.php/uploads/2013043003560sdfsdfl2340.jpg?width=100&height=100&cropratio=1:1&image=/uploads/20130430sdfsdf2340.jpg</foto>
<leeftijd>55</leeftijd>
<geslacht>man</geslacht>
<postuur>Vol</postuur>
<provincie>Belgie</provincie>
<ras>Blank</ras>
<profieltext>Lorem ipsum</profieltext>
<refid>530</refid>
</user>
<user>
<id>422</id>
<nickname>Jackson</nickname>
<url>http://www.abcd.nl/leden/timmerman&refid=530&cp=gg</url>
<foto>http://www.abcd.nl/image.php/uploads/25201842tidsfsrman.jpg?width=100&height=100&cropratio=1:1&image=/uploads/25201842sdfsdf.jpg</foto>
<leeftijd>27</leeftijd>
<geslacht>man</geslacht>
<postuur>Normaal</postuur>
<provincie>Noord-Brabant</provincie>
<ras>Blank</ras>
<profieltext></profieltext>
<refid>530</refid>
</user>