Vista Gadget - 写入 XML 文件
我已经构建了一个 Vista 小工具。它获取一个名为“settings.xml”的本地 XML 文件。 它加载了它并且我改变了一些东西。然后我调用 xmldoc.Save("settings.xml") 方法,该方法在 Internet Explorer 中运行它效果很好...但如果您在侧边栏中运行它,它不会写入 XML - 仅从中加载。
如何让它写入 XML 文件?
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");
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");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在小工具内,部分限定文件名的计算结果为
x-gadget:///
协议。 ActiveXObject对此协议一无所知,因此它们不知道将文件放在哪里并且会抛出错误。使用完全限定的文件名,它应该可以正常工作: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: