I have a couple of input boxes where the user will be entering his/her data .
for example:

Name:-------------
Fathers name:-----------
mothers name:------------

when the user enters the data , i need the xml to be generated something like this

<family>
<name> users name </name>
<fname> fathers name </fname>
<mname> mothers name </mname>
</family>

Hey,
You need to have a HTML form to 'POST' (Submit) the form and a PHP script to generate the file.
The HTML side
call this form.html or something

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Form Page</title>
</head>

<body>
<form name="form1" action="generate.php" method="post">
Name: <input name="name" type="text" /><br/>
Mothers Name: <input name="mname" type="text" /><br/>
Fathers Name: <input name="fname" type="text" /><br/>
<input name="submit" type="submit" value="Submit" />
</form>
</body>
</html>

Then the PHP code to generate the XML
call this generate.php (As per our action in the HTML form)

<?php
header('Content-type: text/xml');//Tell the browser it's an XML document
ob_start();
echo '<?xml version="1.0"?'.'>'."\n";//We have to break up the XML closing tag because [?]> is the closing tag for PHP
echo "<family>
<name>{$_POST['name']}</name>
<fname>{$_POST['fname']}</fname>
<mname>{$_POST['mname']}</mname>
</family>";
?>

that was great .. it really helped me . but supposedly the input is dynamic in nature . i mean if i dont know the number of name inputs , in that case how do i generate the xml data out of it.

Code example do "Dynamic input" please.

here is a basic example of wat i meant by dynamic
the below is a basic form meant ti generate the no of name fields as inputed

<form action="redirect_new.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />
<?php
$val = $_POST['yourname'];
setcookie("name",$val,time()+3600);

for ( $i = 1; $i <= $val ; $i++)
{
?>
<form action="redirect1.php" method="post">
Name: <?php echo $i ?>  <input type="text" name=<?php echo "\"yourname"."$i\""   ?> maxlength="150" /><br />
<?php

} 
?>
<input type="submit" value="Submit" style="margin-top: 10px;" />

the above is the equivalent php code . Now in this case since we dont know the number of name fields to be entered , how do i generate the xml data for this ?

Member Avatar for rajarajan2017

You should generate it from a loop, see the following example which shows the sql data used as to generate xml tags for all records available in the database.

http://www.kirupa.com/web/mysql_xml_php.htm

firstly srry for late reply , for some reason i aint getting notification of reply for the threads i started in daniweb , dunno y.

that is an awesome link .. very helpful .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.