Write an XML file in javascript
<p>I need to write an XML file using Java script. The code I have been able to come up with so far is as below.</p>

<p>function loadXMLDoc(dname) {</p>

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

    var xmlDoc = loadXMLDoc("XMLFile.xml");

    newelm = xmlDoc.createElement("Company");
    newAtt = xmlDoc.createAttribute("Name");
    newAtt.nodeValue = "ABC";

    //newelm.setAttributeNode(newAtt);
    x = xmlDoc.getElementsByTagName("Companies");
    x.appendChild(newelm);
</code></pre>

<p>}</p>

<p>I can see the elements and attributed in xmlDoc object But I am not able to add child elements and attribues to the XML file. Any help is appreciated.</p>

<p>Thanks</p>
