保存格式化的xml

时间:2012-11-21 07:15:31

标签: simplexml domdocument line-breaks formatted

嗨有人可以告诉我为什么这个保存到我的XML文件?它不会返回任何错误,但也不会写入文件?这可能很傻,所以我提前道歉

<?php

$pastor    = $_POST["Speaker"];
$title     = $_POST["Title"];
$link      = $_POST["podcasturl"];
$download  = $_POST["Download"];
$podcastid = $_POST["Podcastid"];
$pubdate   = $_POST ["Date"];

$filename = 'podcast.xml';

$xml = simplexml_load_file($filename);
$xml->addChild('title');
$xml->addChild('pastor', $pastor);
$xml->addChild('title', $title);

function saveXMLFormatted($xml, $filename) {
    $savexml                     = new DOMDocument('1.0');
    $savexml->preserveWhiteSpace = FALSE;
    $savexml->loadXML($xml->asXML());
    $savexml->formatOutput = TRUE;
    file_put_contents($filename, $savexml->saveXML());
}

0 个答案:

没有答案