开发者

PHP's SimpleXML doesn't save edited data

I'm trying to edit some xml data. After this I want to save the data to file.

The problem is 开发者_开发技巧that the edited data isn't saved by simplexml but the node has changed.

$spieler = $xml->xpath("/planer/spieltag[@datum='" .$_GET['date']. "']/spielerliste/spieler");

for ( $i = 1; $i < 13; $i++ ){
    if (!empty($_POST['spieler' .$i ])){
        $spieler[$i-1] = $_POST['spieler' .$i];
    }
}
var_dump($spieler);
$xml->asXML("data.xml");

var_dump() shows the new data, but asXML() doesn't.


Make sure your script has write permission to data.xml


The XPath result array elements aren't PHP ($ref = &$var) references to the actual tree nodes, so this line

    $spieler[$i-1] = $_POST['spieler' .$i];

isn't modifying anything in the tree, you're simply overwriting an entry in a completely independent array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜