在PHP中用循环填充XML
我得到了以下代码,但什么也没发生,我找不到一个关于用多个循环填充XML的好教程:在PHP中用循环填充XML,php,xml,loops,Php,Xml,Loops,我得到了以下代码,但什么也没发生,我找不到一个关于用多个循环填充XML的好教程: 这是你写的吗?只需检查输出myXML.xml,可能您没有对目录的写入权限。保存之前,请尝试查看生成了什么?然后保存。您在哪里使用$username?username是当前登录的用户。我想将他的所有相册和图片打印为.xml中的xml。我只获取带有versionnr的xml标题。。。 $xml = new DOMDocument(); $xml->formatOutput = true; $xml_user
这是你写的吗?只需检查输出myXML.xml,可能您没有对目录的写入权限。保存之前,请尝试查看生成了什么?然后保存。您在哪里使用$username?username是当前登录的用户。我想将他的所有相册和图片打印为.xml中的xml。我只获取带有versionnr的xml标题。。。
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml_user = $xml->createElement("User");
$xml_user->setAttribute("Name", $username);
foreach ($alben as $album) {
$i = 1;
$xml_album = $xml->createElement("Album");
$pictures = $picture_object->get_all_pictures($album['id']);
$xml_user->appendChild($xml_album);
$xml_album->setAttribute("Name", $album['name']);
foreach ($pictures as $picture) {
$xml_picture = $xml->createElement("Picture");
$xml_album->appendChild($xml_picture);
$xml_picture->setAttribute("Name", $picture['name']);
$rating = $rating_object->get_picture_rating($picture['id']);
$xml_rating = $xml->createElement("Rating");
$xml_picture->appendChild($xml_rating);
$comments = $comment_object->get_all_comments($picture['id']);
foreach ($comments as $comment) {
$xml_comment = $xml->createElement("Kommentar");
$xml_picture->appendChild($xml_comment);
$xml_comment->setAttribute("Datum", $comment['date']);
$xml_comment->nodeValue($comment['text']);
}
}
}
$xml->save("myXML.xml");