jQuery的XML分析/操作IE8错误 [英] jQuery XML parsing/manipulation IE8 error

查看:458
本文介绍了jQuery的XML分析/操作IE8错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我加载使用jQuery $不用彷徨的XML文件。加载内容后,我可以操纵它并利用.append追加XML节点,以我自己的元素()。 这适用于Chrome和Firefox,但不是在IE8。

I am loading an XML file using jQuery $.get. after loading the content, i can manipulate it and append the xml nodes to my own elements using .append(). this works on chrome and firefox, but not on IE8.

例如XML文件:

<THEMES>
  <THEME id="city">
    <ASSETS ui="game/city">
        <ASSET package_id="title_screen"        file="title_screen.swf" />
        <ASSET package_id="backgrounds"          file="cartoon_buildings.swf" />
        <ASSET package_id="stand"                file="stand.swf" />
    </ASSETS>
  </THEME>  
</THEMES>

我需要分离所有主题节点,并将其连接到我自己的对象。

I need to detach all of the THEME nodes and attach them to my own object.

下面是我的code精华:

here is the essence of my code:

    var themes = $("<themes></themes>");
    $.get('url/themes.xml', function(data, textStatus, jqXHR) {
        var xml = data;         
        themes.append($(xml).children("themes").children('theme'));
    }, 'xml');

错误发生的时间仅在IE浏览器的themes.append行,这就是日志显示:

The error occurs on the themes.append line only on IE, and this is what the log shows:

不支持此接口

我不能操作和追加XML元素在IE浏览器?

Can i not manipulate and append XML elements on IE?

推荐答案

有2个问题:

  1. 从文档:

  1. From the docs:

查询(HTML [,ownerDocument])
HTML:一个字符串的HTML来动态创建。请注意,这个解析HTML,不是XML

Query( html [, ownerDocument] )
html: A string of HTML to create on the fly. Note that this parses HTML, not XML.

IE浏览器,下面的DOM的规范,不接受的节点文件之间的移动。

IE, following the DOM-specification, does not accept the moving of nodes between documents.

这解决了这两个问题,并在IE的作品对我来说太:

This fixes both issues and works for me in IE too:

    //themes will be a jQuery-Object containing the documentElement
    var themes = $($.parseXML("<themes></themes>").getElementsByTagName('*')[0]);

    $.get('url/themes.xml', function(data, textStatus, jqXHR) {
        var xml = $($.parseXML(data));      
        themes.append(xml.children("themes").children('theme'));        
    }, 'text'
);

这篇关于jQuery的XML分析/操作IE8错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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