javascriptxmlwindows-desktop-gadgets

Vista Gadget - Write to a XML file


I have built a Vista Gadget. It grabs a local XML file called "settings.xml". It loads it and I change a few things. then I call the xmldoc.Save("settings.xml") method which works fine of you run it in Internet Explorer... but if you run it in the sidebar it does not write to the XML - only loads from.

How do I get it to write to the XML file?

        settingsxmldoc = new ActiveXObject("Microsoft.XMLDOM");
        settingsxmldoc.async = false;
        settingsxmldoc.onreadystatechange = readSettingsXML;
        settingsxmldoc.load("settings.xml");

        if (Favorites.length > 0)
        {
            for (i = 0; i < Favorites.length; i++)
            {
                var newElement = settingsxmldoc.createElement("db");
                newElement.appendChild(settingsxmldoc.createTextNode(Favorites[i]));
                favdbs[0].appendChild(newElement);
            }
        }

        settingsxmldoc.save("settings.xml");

Solution

  • Within a gadget, a partially qualified file name evaluates to the x-gadget:/// protocol. ActiveXObjects don't know anything about this protocol, so they don't know where to put the file and they throw an error. Use a fully qualified file name and it should work fine:

    settingsxmldoc.save(System.Gadget.path + "\\settings.xml");