doutui8842 2011-08-03 11:33
浏览 69
已采纳

PHP不使用DOMDocument保存

We'll start off straight forward with the code:

The PHP:

<?php
    $newJaCourse = $_POST["ja-new-course"];
    $newJaSide = $_POST["ja-new-side"];
    $newEnCourse = $_POST["en-new-course"];
    $newEnSide = $_POST["en-new-side"];

    $doc = new DOMDocument('1.0','utf-8');
    $doc->formatOutput=true;
    $doc->preserveWhiteSpace=false;
    echo $doc->load("../../xml/daily_lunch.xml") . "Loaded <br />";

    $japanese = $doc->getElementsByTagName("japanese")->item(0);
    $jacourse = $japanese->getElementsByTagName("course")->item(0);
    $jaside = $japanese->getElementsByTagName("side")->item(0);
    $english = $doc->getElementsByTagName("english")->item(0);
    $encourse = $english->getElementsByTagName("course")->item(0);
    $enside = $english->getElementsByTagName("side")->item(0);

    $jacourse->nodeValue = $newJaCourse;
    $jaside->nodeValue = $newJaSide;
    $encourse->nodeValue = $newEnCourse;
    $enside->nodeValue = $newEnSide;

    $japanese->replaceChild($jacourse,$jacourse);
    $japanese->replaceChild($jaside,$jaside);
    $english->replaceChild($encourse,$encourse);
    $english->replaceChild($enside,$enside);

    echo $doc->save("../../xml/daily_lunch.xml") . "Done!";
?>

My exquisite HTML Form:

        <h4>Change Today's Lunch Menu:</h4>
        <form method="post" action="scripts/lunchupdate.php" name="changelunch">
            <table>
                <tr>
                    <th>Japanese: Course</th>
                    <td><input type="textbox" name="ja-new-course" /></td>      
                </tr>
                <tr>
                    <th>Japanese: Side</th>
                    <td><input type="textbox" name="ja-new-side" /></td>        
                </tr>
                <tr>
                    <th>English: Course</th>
                    <td><input type="textbox" name="en-new-course" /></td>      
                </tr>
                <tr>
                    <th>English: Side</th>
                    <td><input type="textbox" name="en-new-side" /></td>        
                </tr>
            </table>
            <a href="javascript:" onclick="writeNewLunch()">Set Menu</a> |
            <a href="javascript:" onclick="document.changelunch.reset()">Reset Input</a>
        </form>

My Current XML:

<?xml version="1.0" encoding="UTF-8"?>
<lunch featuredisabled="false">
    <japanese>
        <course>
            えびトマトクリームパスタ
        </course>
        <side>
            シーザーサラダ
        </side>
    </japanese>
    <english>
        <course>
            Shrimp and Tomato Cream Pasta
        </course>
        <side>
            Ceasar Side Salad
        </side>
    </english>
</lunch>

Although you can probably tell the purpose, it is to change the items in an XML file. A daily lunch updater for a bilingual restaurant is the goal. My wonderful DOMDocument->save(filename) doesn't do jack though.

Nothing is returned, all my variables and changes echo. I am running PHP5. I looked in phpinfo() and found where all the XML requirements are configured, turned on and not doing their job.

The only thing that comes output form this script is:

Loaded

Done!

  • 写回答

2条回答 默认 最新

  • doutao6380 2011-08-03 11:40
    关注

    Filename is missing. According to the PHP documentation you should have

    $doc->save('myfile.xml');
    

    Do you have permissions to write into folder?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容