Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中用循环填充XML_Php_Xml_Loops - Fatal编程技术网

在PHP中用循环填充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

我得到了以下代码,但什么也没发生,我找不到一个关于用多个循环填充XML的好教程:


这是你写的吗?只需检查输出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");