简体   繁体   English

如何下载DOMparser生成的XML #document?

[英]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()上): 获取的XML文档(像素化不显示数据)

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.

相关问题 如何获取使用 DOMParser 创建的自定义 xml 标记的值? - How can i get the value of a custom xml tag created using DOMParser? Javascript-DomParser-如何确定非XML字符串 - Javascript - DomParser - how to determine non XML string 如何使用 JavaScript 编写文档然后下载文档? - How can I write in a document with JavaScript and then download the document? DOMParser.parseFromString失败,并带有XML5619:不正确的文档语法 - DOMParser.parseFromString fails with XML5619: Incorrect document syntax 以跨浏览器方式使用 Javascript 的 DOMParser 时如何检测 XML 解析错误? - How do I detect XML parsing errors when using Javascript's DOMParser in a cross-browser way? 如何下载使用javascript动态生成的文件列表? - How can I download a list of files dynamically generated with javascript? 如何在DOMParser生成的文档中使用getComputedStyle(没有defaultView或window对象)? - How to use getComputedStyle with DOMParser produced document (no defaultView or window objects)? 如何使用 javascript DOMParser 仅获取 XML 元素而不获取空格? - How do you get only XML elements and not whitespace with the javascript DOMParser? 如何访问xml2js生成的对象中的集合 - How can I access collections in an object generated by xml2js 如何在 Django 项目中下载使用 python-docx 生成的文档? - How to download a document generated with python-docx in Django project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM