Click here to Skip to main content
15,896,606 members

Comments by DivyaNaidu486 (Top 5 by date)

DivyaNaidu486 10-Oct-14 6:33am View    
Thanks for the code but it will not help me as i am not suppose to use .aspx pages, my requirement is transferring Html form data (using javascript) to xml file.
DivyaNaidu486 10-Oct-14 6:02am View    
Deleted
I have tried with below code,even this is not working !!!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Storing In XML</title>
</head>
<body>
<form id="myform" name="myform" action="#" method="get">
XML Document:<br />
<textarea id="showxml" name="showxml" rows="10" cols="40"></textarea>
<br /><br /><br />
Subject: <input id="namefield" type="text" name="namefield"><br>
Attachment: <input id="attachfield" type="text" name="attachfield"><br>
<input type="Submit" value="add record" önclick="addElement();document.myform.showxml.value='';
display(xmldoc.documentElement);" />
<input type="button" value="redisplay XML document"
önclick="document.myform.showxml.value='';
display(xmldoc.documentElement);" />
</form>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","page1.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

function addElement()
{
var rootElement = document.documentElement;

var sname = document.getElementById('namefield').value;
var aname = document.getElementById('attachfield').value;


/* create subject element*/
var newSubject = document.createElement('subject');


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

var newAttachment = document.createElement('aname');
var newAttachmentText = document.createTextNode(aname);
newTitle.appendChild(newAttachmentText);
newEmployee.appendChild(newAttachment);



/* append completed record to the document */
rootElement.appendChild(newSubject);
xmlDoc.save("page1.xml")
}


</body>
</html>
DivyaNaidu486 10-Oct-14 5:50am View    
Deleted
Hi, i have tried different codes ,one of them is here below
<html>
<head>
<title>Test</title>
<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 + '" ');
file.WriteLine('></Person>\n');

file.WriteLine('</personinfo>\n');
file.Close();
}
</script>
</head>
<body>
Name :
<input type="text" name="name" value="" id="txtname" /><br />
Address :
<input type="text" name="id" value="" id="txtadd" /><br />
Age:
<input type="text" name="write" value="" id="txtage" /><br />
<input type="button" onclick="SaveXMLData()" value="submit";
</body>
</html>
the above code generates an xml file but everytime it rewrites the inserted row, i mean it does'nt append the rows in xml file it always creates a new row deleting the previous once,
i need the xml file to append rows in it each time we execute html file.this code works only with IE when you change the settings in IE
I.E.
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

plz help me out!!!
DivyaNaidu486 10-Oct-14 3:17am View    
Hi Tadit,
The code i have used is
<html>
<head>
<title>Test</title>
<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 + '" ');
file.WriteLine('></Person>\n');

file.WriteLine('</personinfo>\n');
file.Close();
}
</script>
</head>
<body>
Name :
<input type="text" name="name" value="" id="txtname" /><br />
Address :
<input type="text" name="id" value="" id="txtadd" /><br />
Age:
<input type="text" name="write" value="" id="txtage" /><br />
<input type="submit" onclick="SaveXMLData()" />
</body>
</html>
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

DivyaNaidu486 9-Oct-14 8:59am View    
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!!!