anf.etienne Posted March 13, 2009 Share Posted March 13, 2009 how can i generate xml using data from a form? I've got my code that generates the xml, but i haven't got a clue how to get a form to submit so the childs in the xml are filled in automatically using the data collected from a form. I've that i have to put the child in a loop but i don't know where to start.....can someone point me in the right direction? thanks here is my code # <?php # # $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gallery></gallery>"; # $xmlobj = simplexml_load_string($xmltext); # # $i=1; # # $nameCaps = $xmlobj->addChild("pic"); # $nameCaps->addAttribute("name", "PHOTO 1"); # $nameCaps->addAttribute("caption", "This is the space where you can put in your own customised caption for each image."); # # print header("Content-type: text/plain") . $xmlobj->asXML(); # # ?> Link to comment https://forums.phpfreaks.com/topic/149294-solved-generate-xml/ Share on other sites More sharing options...
anf.etienne Posted March 13, 2009 Author Share Posted March 13, 2009 i figured out how to generate xml from a form using php. here is the code <?php if(isset($_POST['create_xml'])){ $picT = $_POST['picT']; $photoT = $_POST['photoT']; $captionT = $_POST['captionT']; $randT = $_POST['randT']; $xmltext = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<gallery></gallery>"; $xmlobj = simplexml_load_string($xmltext); $nameCapsA = $xmlobj->addChild("$picT"); $nameCapsA->addAttribute("name", "$photoT"); $nameCapsA->addAttribute("caption", "$captionT"); $path_dir = "xmlf/"; $path_dir .= $randT .".xml"; /* Data in Variables ready to be written to an XML file */ $fp = fopen($path_dir,'w'); $write = fwrite($fp,$xml_document); print header("Content-type: text/plain") . $xmlobj->asXML(); } ?> Link to comment https://forums.phpfreaks.com/topic/149294-solved-generate-xml/#findComment-784120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.