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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里