Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<!DOCTYPE html>
<html>
  <head>
    
    <script type="text/javascript">
	
	  function addElement()
	  {
		var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
		var root;
		var newNode;
		xmlDoc.async = false;
		xmlDoc.resolveExternals = false;
		xmlDoc.load("user.xml");

		try
		       {   
				   root = xmlDoc.documentElement;
				   alert(root.xml);
				   
				    var n1 =document.getElementById("t1").value;
				    var p1 =document.getElementById("t2").value;
				    newNode = xmlDoc.createElement("user");
                
				    var name =xmlDoc.createNode(1, "name", n1);
					var pass = xmlDoc.createNode(1, "pass", p1);
					
                    newNode.appendChild(name);
				    newNode.appendChild(pass);
					
				   
				    root.appendChild(newNode);
				  
				 
				 
				 
				 
				   alert(root.xml);
				   
				
				 xmlDoc.save("user.xml");
				 document.WriteString(root.lastChild.nodeValue);
				   alert("added");
				   
				}
		catch(e)
				 {
				   alert("error");
				 }
		}
		
	</script>
	 
	  </head>
	  <body>
		   <form id="user_form" method="post">
			  <table>
				<tr>
				<td>Name :</td><td><input type="text" id="t1"></td>
				</tr>
				<tr>
				<td>Password :</td><td><input type="text" id ="t2"></td>
				</tr>
				<tr>
				 <td><input type ="Submit" id="b1"  önclick="addElement()"></td>
				</tr>
			  </table>
		   </form>
	  </body>
</html>
Posted
v2
Comments
Do you see any errors listed on the console of Developer Tool?
Member 10471898 18-Jul-14 6:31am    
Yes, a error message pop up after this
xmlDoc.save("user.xml");
means some exception occurs
What is that Error?
Member 10471898 18-Jul-14 7:43am    
only "error" alert box pop up, without any detail

1 solution

Hey,
please add a line of code xmlDoc.DocumentElement.AppendChild(newNode); just before xmlDoc.save("user.xml");


Now your code will be like:

........

C#
xmlDoc.DocumentElement.AppendChild(newNode);
xmlDoc.save("user.xml");


........
 
Share this answer
 
Comments
Member 10471898 22-Jul-14 7:33am    
Not working.............

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