使用jQuery解析复杂的XML

我正在尝试使用以下jQuery解析以下XML。 页面上没有显示任何内容。 我知道它正在获取文件。 我在网上看过,虽然有许多用jquery解析xml的例子,但它们看起来都不像这种格式。

XML:

   <img src='[!--$wcmUrl&amp;x28;'resource','CMS3_130980'&amp;x29;--]'/> <img src="[!--$wcmUrl('resource','CMS3_132821')--]"/> <p> Paragraph of text goes here.<br /><br /> Paragraph of text goes here.<br /><br /> Paragraph of text goes here.<br /><br /> Paragraph of text goes here.<br /><br /> Paragraph of text goes here.</p>   

HTML和jQuery:

    $(document).ready(function () { $.ajax({ type: "GET", url: "link_to_my_file.xml", dataType: "xml", success: parseXml }); }); function parseXml(xml){ $(xml).find("wcm\\3a root").each(function(){ alert("Test"); $("#output").append($(this).attr("title") + "
"); $("#output").append($(this).attr("wide_image") + "
"); $("#output").append($(this).attr("image") + "
"); $("#output").append($(this).attr("body") + "
"); }); };

你必须在选择器中逃避 : http : //mothereff.in/css-escapes#1wcm%3Aroot

所以,而不是:

 $(xml).find("wcm:root") 

使用:

 $(xml).find("wcm\\3a root") 

此外,您的代码段在parseXml函数声明之后是无效的JavaScript(缺失)。 检查错误控制台。