1
Answer

Using Javascript to save an xml file

jayaprakash R

jayaprakash R

14y
2.6k
1

Hi all,
I want to save an xml file using javascript. and also is it possible to access the local file sytem using javascript.
Here I am just trying to delete a node from xml file and save the xml file.
function deleteNode() {
    var xmlDoc;
    var txt;
    var nodes;
    var c;
    var parents;
   xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
    xmlDoc.load("wkflow.xml")
    nodes = xmlDoc.getElementsByTagName("Activity");
    for (i = 0; i < nodes.length; i++)
    {
        txt = xmlDoc.getElementsByTagName("Activity")[i].getAttribute("ID");
        c =xmlDoc.getElementsByTagName("Activity")[i];
        if (txt == outsideFunction.pid) {
        c.parentNode.removeChlid(c);
        xmlDoc.save("C:\\Temp\\wkflow.xml"); ---here was the problem

or
      xmlDoc.save("wkflow.xml");--- here was the problem
                                
                        
     }
Xml- sample
<act>
<Activity id=10>x</Activity>
<Activity id=10>x</Activity>
</act>
 
Answers (1)
0
Ankit Sharma

Ankit Sharma

NA 8.8k 140.9k 7y
Hi ,
 
This code has errors.
 
You are using  s[i].total=0; 
 
This won't work coz
 
1. s is not an array 
2. you have not set any values to the int variable i 
 
You have to create an array of structure like this
 
struct student arr[10]; 
 
then you have to iterate loop to set values
 
Now scanf("%s",&s[i].name); is also wrong as format '%s' expects argument of type 'char *', but here it has type 'char (*)[20]'
 
change it to
 
scanf("%s",s[i].name); 
 
Please make these changes and let me know if any issues
 
I have edited the code and you can find the fully edited and working code here
 
https://ide.geeksforgeeks.org/sYBZrfXFZ9