【发布时间】:2011-06-08 10:02:47
【问题描述】:
我有一个 xml 文件,其中包含我使用 jquery ajax 解析的 html 标签。 我可以毫无问题地获取文本值。如何获取元素中的 html 部分?
编辑:我尝试将 html 包装在 cdata 中,但希望将 xhtml 包含在 xml 中。
$.ajax({ type: "GET",
url: "product.xml",
dataType: "xml",
success: function (xml) {
$(xml).find("product[productid=" + selection + "]").each(function () {
var $title = $(this).find("title").text(); //get title
var $desc = $(this).find("description").html(); //get description
//$('[nodeName=]',xml)
$("#producttitle").html("");
$("#productdesc").append($desc);
$("#producttitle").append($title);
});
}
<product productid="1">
<title>Active Directory</title>
<status>noinfo</status>
<description>
Headline
<b>tester</b>
<ul>
<li>test list element</li>
</ul>
</description>
<link title=""></link>
</product>
干杯, 特里
【问题讨论】:
-
嗯基本上是通常的 jquery.ajax $.ajax({ type: "GET", url: "product.xml", dataType: "xml", success: function (xml) {... . 我用 var $desc = $(this).find("description").text(); 得到值;
标签: jquery xml html-parsing