改變一個XML值這是我的XML文件:不能與PHP
<todos>
<todo>
<titel>sasd</titel>
<erstellt>2012-04-30 17:19:21</erstellt>
<erledigen_bis>2012-05-03</erledigen_bis>
<erledigt>Nein</erledigt>
<thingstodo>sffsdfdf</thingstodo>
</todo>
</todos>
現在我想改變<erledigt>
標籤爲「JA」內的值。
我試圖與下面的代碼:
<?php
$filename = 'xml/todos.xml';
$xmlDoc = new DOMDocument();
$xmlDoc->load('xml/todos.xml');
$todos = $xmlDoc->getElementsByTagName('todo');
foreach ($todos as $todo) {
$titel = $todo->getElementsByTagName('titel');
$actualTitel = $titel->item(0)->nodeValue;
$paramTitel = $_GET["titel"];
$erstellt = $todo->getElementsByTagName('erstellt');
$actualTimestamp = $erstellt->item(0)->nodeValue;
$paramTimestamp = $_GET["timestamp"];
if ($paramTitel == $actualTitel && $paramTimestamp == $actualTimestamp) {
$todo->erledigt= 'Ja';
}
}
$xmlDoc->save($filename);
header('Location: todo.php');
?>
請幫助我,我搜索在網絡上約5小時,找不到我的問題的任何解決方案。
謝謝你這麼多,你從一個不眠之夜救了我! – alderos
不客氣:-) –