Click here to Skip to main content
14,733,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a html form in which user fills the data.
That data is shown in xml file using javascript.
Shubhashish_Mandal 14-Mar-13 2:04am
you need a xml parser to create a xml file along with the form data. I just google it with "javascript to create xml" and I get answer.
What have you tried so far ?
Post some code.
DivyaNaidu486 9-Oct-14 8:59am
someone plz help me, i have tried this code but i am not able to generate page1.xml file,even if i create page1.xml file manually, records are not getting appended to it from html page.Thanks in advance!!!
Hi Divya,

Please add another question describing your scenario and to support that, add some code snippets.

In that way, you will get more answers. Nobody would reply here because this is one old thread.

DivyaNaidu486 10-Oct-14 3:17am
Hi Tadit,
The code i have used is
<script type="text/javascript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FILENAME = 'D:\\IE Try\\PersonXML2.xml';

function SaveXMLData() {
var file = fso.CreateTextFile('D:\\IE Try\\PersonXML2.xml', true);
file.WriteLine('<!--?xmlversion="1.0" encoding="utf-8" ?-->\n'); file.WriteLine('<personinfo>\n');

file.Write(' <Person ');
file.Write('Name="' + document.getElementById('txtname').value + '" ');
file.Write('Address="' + document.getElementById('txtadd').value + '" ');
file.Write('Address="' + document.getElementById('txtage').value + '" ');

Name :
<input type="text" name="name" value="" id="txtname" /><br />
Address :
<input type="text" name="id" value="" id="txtadd" /><br />
<input type="text" name="write" value="" id="txtage" /><br />
<input type="submit" onclick="SaveXMLData()" />
The above code is generating an XML file ,every time i execute the html file it generates a new xml file with one row of data in it.
I need to append data to xml file , i mean every-time i execute html file ,it should add a new row to the same xml file.
Hope you will help me out with this!!!
and thanx for your Reply.
one more thing,the above code which i have posted runs only in IE Browser, that too after making some settings in IE.
settings are
In order to run safely you need to change setting of IE.

1. Go to Tools > Internet options > Security > Custom Level
2. Under the ActiveX controls and plug-ins, select Enable for Initializing and Script ActiveX controls not marked as safe

Hi Divya,

Please add another question describing your scenario and to support that, add some code snippets.

In that way, you will get more answers. Nobody would reply here because this is one old thread.

priya2013 14-Mar-13 5:23am
i hav tried this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>

New Web Project Page

<form id="myform" name="myform" action="#" method="get">
XML Document:<br />
<textarea id="showxml" name="showxml" rows="10" cols="40"></textarea>
<br /><br /><br />
Name: <input type="text" name="namefield" id="namefield" size="50" /><br />
Title: <input type="text" name="titlefield" id="titlefield" size="30" />
<br />
Phone: <input type="text" name="phonefield" id="phonefield" size="20" />
<br />
Email: <input type="text" name="emailfield" id="emailfield" size="20" />
<br />

<input type="button" value="add record"
display(xmldoc.documentElement);" />

<input type="button" value="delete last record"
display(xmldoc.documentElement);" />

<input type="button" value="redisplay XML document"
display(xmldoc.documentElement);" />
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
function addElement()
var rootElement = document.documentElement;

var name = document.getElementById('namefield').value;
var title = document.getElementById('titlefield').value;
var phone = document.getElementById('phonefield').value;
var email = document.getElementById('emailfield').value;

/* create employee element*/
var newEmployee = document.createElement('employee');

/* create child elements and text values and append one by one */
var newName = document.createElement('name');
var newNameText = document.createTextNode(name);

var newTitle = document.createElement('title');
var newTitleText = document.createTextNode(title);

var newPhone = document.createElement('phone');
var newPhoneText = document.createTextNode(phone);

var newEmail = document.createElement('email');
var newEmailText = document.createTextNode(email);

/* append completed record to the document */

priya2013 14-Mar-13 5:24am
can u just send me the link from where u gt it
Shubhashish_Mandal 14-Mar-13 9:04am
to whom you ask this?
priya2013 15-Mar-13 0:39am
i ask u shubhashish to send me the link
Shubhashish_Mandal 22-Mar-13 6:16am
I told you before in my first comment to google it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900