Javascript 如何将表附加到xml文件?

Javascript 如何将表附加到xml文件?,javascript,xml,html,xml-parsing,Javascript,Xml,Html,Xml Parsing,我希望能够将带有一组属性的整个表附加到xml文件中,以便以后能够检索它们。我面临的唯一问题是写入XML文件,而当我对存储的值调用alert()时,它们的设置是正确的 这是我的密码: function getXML(positionX, positionY, canvasWidth, canvasHeight) { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () {

我希望能够将带有一组属性的整个表附加到xml文件中,以便以后能够检索它们。我面临的唯一问题是写入XML文件,而当我对存储的值调用alert()时,它们的设置是正确的

这是我的密码:

  function getXML(positionX, positionY, canvasWidth, canvasHeight) {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            xmlParse(xhttp);
            addToXml(xhttp, positionX, positionY, canvasWidth, canvasHeight);

        };
        xhttp.open("GET", "index.xml", true);
        xhttp.send();
    };




     function addToXml(xml, positionX, positionY, canvasWidth, canvasHeight) {
            var xmlFile = xml.responseXML;
            var table = xmlFile.createElement("table"),
                x = xmlFile.createAttribute("positionX"),
                y = xmlFile.createAttribute("positionY"),
                width = xmlFile.createAttribute("tableWidth"),
                height = xmlFile.createAttribute("tableheight");
            x.nodeValue = positionX;
            y.nodeValue = positionY;
            width.nodeValue = canvasWidth;
            height.nodeValue = canvasHeight;


            table.setAttributeNode(x);
            table.setAttributeNode(y);
            table.setAttributeNode(width);
            table.setAttributeNode(height);

            xmlFile.getElementsByTagName('Tables')[0].appendChild(table);
            alert(xmlFile.getElementsByTagName('table')[0].getAttribute('positionX'));

        }