Xml使用jQuery调用(无效的XML) [英] Xml Calling with jQuery, (invalid XML)

查看:104
本文介绍了Xml使用jQuery调用(无效的XML)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我想从XML文件中获取一些数据(如果我可以说它是XML文件),使用jQuery:

I have one problem , I want to get some data from XML file (if I can say that it is XML file), with jQuery:

这是我的jQuery,它与普通的XML文件一起工作:

This is my jQuery, it works with normal XML file :

$.ajax({
        type: "GET",
        url: "test.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('result').each(function(){
            var bid = $(this).find('bid').text();
            alert(bid);
            });
            }
        });

但这是数据:

But this is the data:

   <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
<?xml version="1.0" ?> 


<T_transmission> 
<result> 
<last>9.9200</last> 
<bid>9.9000</bid> 
<ask>9.9200</ask> 
<mid>9.9100</mid> 
</result> 

 </T_transmission>

</string>

因为它有< string ...> 它不起作用...

Because it has "<string ...> it doesn't work ...

有人可以建议如何解决它,或者有另一种方法来解决...

Can somebody suggest how to fix it or maybe there are another way to fix ...

非常感谢!!!!!!

Thanks a lot !!!!!!

推荐答案

如果xml格式完全在你的控制之外,你可以像这样攻击它。这在FireFox中是适用的。

If the xml format is totally outside your control you could hack it a bit like so. This worked for me in FireFox.

$.ajax({
  type: "GET",
  url: "test.xml",

  // change dataType to 'text' so that jquery doesn't try to parse xml
  dataType: "text",
  success: function(xml) {

    // just remove the declaration using replace()
    xml = xml.replace('<?xml version="1.0" ?>', '');

    $(xml).find('result').each(function(){
    var bid = $(this).find('bid').text();
    alert(bid);
    });
  }
});

这篇关于Xml使用jQuery调用(无效的XML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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