如何创建 IXMLDOMDocument2,或以其他方式将其 IXMLDOMElement 之一添加到 [Object, Document]?
仅当我尝试将一个元素从一个文档添加到另一个文档时,我才会在 IE9 中收到 HIERARCHY_REQUEST_ERR (3) 错误。 我正在按如下方式创建我的文档:
var xmlDoc = document.implementation.createDocument("","root",null);
并尝试按如下方式添加到它:
$(otherDoc).find("selector_for_nodes_I_want").each(function(){
$(xmlDoc).find("root").append($(this).remove());
});
Firefox 和 Chrome 对此很好,但 IE9 不喜欢它。这个想法是 xmlDoc 是 otherDoc 的过滤版本,我将其作为字符串存储在 sessionStorage 中。我希望以这种方式保存 XMLHTTPRequests。我不太热衷于先将 otherDoc 转换为字符串,然后通过 $.parseXML() 转换回来。我希望有更好的选择,或者如果我的想法是错误的,我也会听到这样的争论。 谢谢。
代替OP的答案,是否有人对为什么需要使用 domParser()
或 $.parseXML(jqXHR.responseText)
有一个不错的解释当响应头是 xml时:Content-Type:text/xml;字符集=utf-8
。为什么 IE9 猜测我想使用这个荒谬的 IXMLDOMDocument2
实现来解析我的响应?
I'm getting an HIERARCHY_REQUEST_ERR (3) in IE9 only when I try to add an element from one document to the other.
I'm creating my document as follows:
var xmlDoc = document.implementation.createDocument("","root",null);
and trying to add to it as follows:
$(otherDoc).find("selector_for_nodes_I_want").each(function(){
$(xmlDoc).find("root").append($(this).remove());
});
Firefox, and Chrome are fine with this, but IE9 doesn't like it. The idea is that xmlDoc is a filtered version of the otherDoc, which I will store as a string in sessionStorage. I'm hoping to save XMLHTTPRequests this way. I'm not too keen on the option of converting otherDoc to a string first, then converting back via $.parseXML(). I'm hoping for a better option, or if I'm thinking about this all wrong, I'd hear that argument as well.
Thanks.
In lieu of an answer for the OP, is there anyone with a decent explanation as to why it is necessary to use domParser()
or $.parseXML(jqXHR.responseText)
when the response header is xml already: Content-Type:text/xml; charset=utf-8
. Why does IE9 guess that I want to use this ridiculous IXMLDOMDocument2
implementation to parse my response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论