3

i have function readXML that will read the value from given xml file and it will replace specific node value , after replacing the specific value, same thing has to be reflected the raw file( I mean books.xml file), after doing the modification how to save the content in xml file.

Ex: Code for replacing node.

function readXML() {

        xmlDoc = loadXMLDoc("books.xml");

        x = xmlDoc.documentElement;

        //create a book element, title element and a text node
        newNode = xmlDoc.createElement("book");
        newTitle = xmlDoc.createElement("title");
        newText = xmlDoc.createTextNode("A Notebook");

        //add the text node to the title node,
        newTitle.appendChild(newText);
        //add the title node to the book node
        newNode.appendChild(newTitle);

        y = xmlDoc.getElementsByTagName("book")[1]
        //replace the first book node with the new node
        x.replaceChild(newNode, y);

        z = xmlDoc.getElementsByTagName("title");
        for (i = 0; i < z.length; i++) {
            alert(z[i].childNodes[0].nodeValue);

        }

       //Here i have to save the xmlDoc in my local system.

    }

    function loadXMLDoc(dname) {
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        }
        else {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET", dname, false);
        xhttp.send();
        return xhttp.responseXML;
    }

I am new to XML.

1
  • If you want to save it on the server side, you will have to upload the manipulated file and store it with serverside logic. Commented Jan 8, 2014 at 14:08

1 Answer 1

5

You can download it using FileSaver

var blob = new Blob([xmpString], {type: "text/xml"});

saveAs(blob, "test.xmp");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.