Jump to content

Archived

This topic is now archived and is closed to further replies.

sso

php simple xml

Recommended Posts

Hey all,

I am writing a php-gtk app and I am reading a xml file in to represent the users todo list. My problem is i can read the file in fine, but i do not know how to change the xml file when the user changes part of it..

here is a little bit of code..
function create_tree()
    {
    //------------------load the tasks ------------------
        $toDoList = simplexml_load_file('list2.xml');
        //-------------------end loading tasks --------------
       
        //add some data to the data store
        foreach ($toDoList->task as $task)
        {
        // i add stuff to show it on the screen
        }   
    }

... these code here will allow me to add or append to the xml file
$toDoList = simplexml_load_file('list2.xml');
            $index = 0;
       
        foreach ($toDoList->task as $task)
        {       
$intID = (int)$task->id;
        if ($index <= $intID)
        {
        $index = $intID +1;
        }
        }
            echo $index;
            $newTask = $toDoList->addChild('task');
            $newTask->addChild('id',$index);
    $newTask->addChild('done', 0);
    $newTask->addChild('toDo', $toDo);
    $newTask->addChild('priority',$priority);
    $newTask->addChild('date',$dateString);
    file_put_contents('list2.xml',$toDoList->asXML());

But what i am really hoping for is to be able to edit the xml file so when the user clicks done on a certain task I can write that to xml .

Would appreciate any ideas or directions on where to go.

Kind regards,
Sso

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.