如何从jQuery(跨浏览器)返回的XMLDocument中获取整个XML字符串? [英] How do I get the entire XML string from a XMLDocument returned by jQuery (cross browser)?

查看:325
本文介绍了如何从jQuery(跨浏览器)返回的XMLDocument中获取整个XML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过,并且未能找到如何从GET返回的XMLDocument中获取整个XML字符串。关于如何查找或替换对象中的特定元素,有很多问题,但我似乎无法找到任何答案,以便如何将整个文档作为字符串获取。

I have tried and failed to find out how to get the entire XML string from the XMLDocument returned by a GET. There are a lot of questions on SO on how to find or replace specific elements in the object, but I can't seem to find any answer to how to get the entire document as a string.

我正在使用的示例来自此处。 用xml做些事情这一部分就是我目前所处的位置。我觉得这应该是非常微不足道的,但我不明白如何。是否有可用于此目的的xml.data()或类似内容?

The example I'm working with is from here. The "do something with xml"-part is where I'm at at the moment. I get the feeling that this should be really trivial, but I fail to find out how. Is there an "xml.data()" or similar that can be used for this purpose?

$.ajax({
    url: 'document.xml',
    type: 'GET',
    dataType: 'xml',
    timeout: 1000,
    error: function(){
        alert('Error loading XML document');
    },
    success: function(xml){
        // do something with xml
    }
});

用例是我想将xml提供给flash插件,为此我需要实际XML作为字符串。

The use case is that I want to feed the xml to flash plugin and for that I need the actual XML as a string.

推荐答案


我需要实际的XML作为字符串

I need the actual XML as a string

您希望它是纯文本而不是XML对象吗?将 dataType 'xml'更改为'text'>。有关更多选项,请参阅 $ .ajax文档

You want it as plain text instead of XML object? Change dataType from 'xml' to 'text'. See the $.ajax documentation for more options.

这篇关于如何从jQuery(跨浏览器)返回的XMLDocument中获取整个XML字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆