更新时间:2022-10-15 09:19:27
已经有一段时间了,但我只是意识到我忘了发布我如何解决您的组合想法的问题。
$我需要一个完整的客户端数据库(没有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.