Jump to content

[SOLVED] generate xml


anf.etienne

Recommended Posts

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

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
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.