Appending an XML File Using PHP -
i have php file contains html form. when user enters info form, carries out error checking , if in order info entered written xml file in specific order. part works perfectly. problem when user fills in form again, need new info append xml file (not overwrite it). currently, on writes data, help me out on how this? tried watching tutorials new xml , found them confusing. xml file follows;
<?php function createfile($xml_file) { $filemessageid = $_post['messageid']; $filecreation = $_post['filedatetime']; $filetransactions = $_post['filetransactions']; $filecontrolsum = $_post['filecontrolsum']; $cid = $_post['cid']; // create new dom document $xml = new domdocument(); // these lines create nicely indented xml file $xml->preservewhitespace = false; $xml->formatoutput = true; // create root element, , add together dom addroot($xml); // add together more elements xml file $customerddinfo = $xml->createelement("cstmrdrctdbtinitn"); // add together element root $xml->documentelement->appendchild($customerddinfo); // create elements $groupheader = $xml->createelement("grphdr"); $initiatingparty = $xml->createelement("initgpty"); $identificationheading = $xml->createelement("id"); $privateidentification = $xml->createelement("prvtid"); $other = $xml->createelement("othr"); // append these elements friend $customerddinfo->appendchild($groupheader); $groupheader->appendchild($xml->createelement('msgid', $_post['messageid'])); $groupheader->appendchild($xml->createelement('credttm', $_post['filedatetime'])); $groupheader->appendchild($xml->createelement('nboftxs', $_post['filetransactions'])); $groupheader->appendchild($xml->createelement('ctrlsum', $_post['filecontrolsum'])); $groupheader->appendchild($initiatingparty); $initiatingparty->appendchild($identificationheading); $identificationheading->appendchild($privateidentification); $privateidentification->appendchild($other); $other->appendchild($xml->createelement('id', $_post['cid'])); $customerddinfo->appendchild($paymentinformation); // save dom document xml file $xml->save($xml_file); } function addroot(&$xml) { $xml->appendchild($xml->createelement("entry")); } // phone call xml function createfile('sepa.xml'); //redirect give thanks page header ('location: thankyou.php'); ?> load existing xml document (if there one) add kid @ right level info append
an xml not text file, set other info @ bottom of it. in xml have set info within node somewhere within existing xml.
<examplexml> <item> <name></name> <number></number> <date></date> </item> </examplexml> when item xml should load xml, take 'examplexml' node , append kid it. result:
<examplexml> <item> <name></name> <number></number> <date></date> </item> <item> <name></name> <number></number> <date></date> </item> </examplexml> i don't work xml dom in php can't provide code. @ http://www.php.net/manual/en/class.domdocument.php right functions.
php xml append
No comments:
Post a Comment