如何在jQuery中通过DOM查询XML字符串 [英] How to query an XML string via DOM in jQuery
问题描述
我这样做:
var t =< div>< outer>< inner> abc< / inner>< inner> def< / inner>< / outer>< / div> ;;
alert([+ $(t).find(outer)。html()+]);
在Firefox 3中打印:
[< inner> abc< / inner>< inner> def< / inner>]
在IE 7中,它打印:
[]
任何解决方案可以让浏览器工作?
谢谢。
已经有一段时间了,但我只是意识到我忘了发布我如何解决您的组合想法的问题。
$我需要一个完整的客户端数据库(没有PHP)。我创建了一个包含XML的HTML注释的div 。我使用此HTML解析HTML注释,然后将XML转换为JSON这个。
var xmltext = $(#piecelist)。
var json = $ .xml2json(xmltext.html());
您可以在这里查看我的方法:
http://wesculpt.net/art.html
也许我应该转这个方法变成一个jQuery插件。
感谢大家的帮助。
I would like to take a string and treat it as XML. Then I will be able to query with DOM via the jQuery.find. Everything was working fine in Firefox, but I realized this is not working in IE.
I am doing this:
var t = "<div><outer><inner>abc</inner><inner>def</inner></outer></div>";
alert("[" + $(t).find("outer").html() + "]");
In Firefox 3 it prints:
[<inner>abc</inner><inner>def</inner>]
In IE 7 it prints:
[]
Any workarounds for getting this to work across browsers?
Thanks.
It's been a while, but I just realized that I forgot to post how I solved the problem with your combined ideas.
I needed an entirely client side database (no PHP).
I created a div with an HTML comment in it containing the XML. I parsed the HTML comment with this and then I converted the XML to JSON with this.
var xmltext = $("#piecelist").comments();
var json = $.xml2json(xmltext.html());
You can see my method in action here: http://wesculpt.net/art.html
Maybe I should turn this method into a jQuery plugin.
Thanks for all your help everyone.
这篇关于如何在jQuery中通过DOM查询XML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!