Jump to content

php simple xml


sso

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.