[英]How can I download a XML #document generated by DOMparser?
Good morning. 早上好。
I have a webpage with a form that generates a XML Document with DOMparser(). 我有一个网页,其中包含使用DOMparser()生成XML文档的表单。 That's the function to get the XML:
这是获取XML的功能:
function textToXML(text) {
try {
var xml = null;
if (window.DOMParser) {
var parser = new DOMParser();
xml = parser.parseFromString(text, "application/xml");
var found = xml.getElementsByTagName("parsererror");
if (!found || !found.length || !found[0].childNodes.length) {
return xml;
}
return null;
} else {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(text);
return xml;
}
} catch (e) {
// suppress
}
}
And I get a XML document like (displayed on console.log()): 我得到一个XML文档(显示在console.log()上):
And I don't know how could I download it now, I have tried with 而且我不知道我现在怎么下载它,我试过了
location.href='data:application/download,' + encodeURIComponent(xmlFile)
but the downloaded file just show something like "[object] Object". 但下载的文件只显示“[object] Object”之类的内容。
I GOT IT. 我知道了。 Finally I was searching for a plugin and I got this https://github.com/eligrey/FileSaver.js !!
最后我正在寻找一个插件,我得到了这个https://github.com/eligrey/FileSaver.js !! I hope it help somebody more than me!
我希望它比我更有帮助! Thanks for try to help me!
谢谢你试着帮助我!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.