Saving form data to xml

Discussion in 'PHP' started by mikmik, Nov 14, 2005.

  1. #1
    He he, I am new at this one, thanks for your patience:eek:

    I am trying to save for data to an existing xml file. All the fields are input into their own tags in the xml, ie. they are not to be saved as attributes (for now).

    I can write using 'a+' like this:
    // Set the string to be written to the file
    $values = "<name>: $fName $lName\r\n" </name>;
    $values .= "<age:> $age\r\n" </age>;
    
    // Open the file for truncated writing
    $fp = @fopen("organizer.data", "a+") or die("Couldn't open organizer.data for writing!");
    $numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!");
    Code (markup):
    I want to insert the tags before the root closing tag in the xml, say it is </person>.

    I am thinking append at 'lastChild' or something, but I do not know how to insert the curser in the correct position without killing the xml file!

    Is there a simple command using fopen, etc., or do I need to parse the DOM?

    Thanks very much, this is very new to me.
     
    mikmik, Nov 14, 2005 IP
  2. mikmik

    mikmik Guest

    Messages:
    356
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Perhaps?
    $root = $doc->add_root('members');
    $member = $root->new_child('member','');
    Code (markup):
    http://www.developerfusion.co.uk/show/3944/

    here we go:
    $root = $doc->append_child($root);
    Code (markup):
    Here is a wicked tutorial: Build an XML-Based Content Management System with PHP - Sitepoint
     
    mikmik, Nov 14, 2005 IP