开发者

PHP's SimpleXML doesn't save edited data

开发者 https://www.devze.com 2023-01-16 14:45 出处:网络
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.

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

精彩评论

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

关注公众号