假设我得到了一个place_categories.xml文件,如下所示,这是一个纯xml文件,不能从任何数据库中检索到:
<category>
<pcid>23533</pcid>
<name>Designer Clothing Shop</name>
<sub_category>shopping</sub_category>
</category>
<category>
<pcid>23540</pcid>
<name>Dim Sum Restaurant</name>
<sub_category>food & drink</sub_category>
</category>如何查找:选择名称,sub_category where pcid=23540 in 和JQuery并生成
迪姆森餐厅
食品饮料
发布于 2012-05-01 08:33:02
如果您想避免使用XPath,可以尝试这样的方法:
$.ajax({
type: "GET",
url: "place_categories.xml",
dataType: "xml",
success: function parseXml(xml)
{
//find every Tutorial and print the author
$(xml).find("rootnode").each(function() {
if($(this).find("pcid").text()==="23540") {
console.log($(this).find("sub_category").text());
}
});
}
});发布于 2012-05-01 08:28:59
jQuery和XPath --但我不知道PHP与此有什么关系:
$(document).ready( function(){
$.get( "http://localhost/~gregory/place_categories.xml",
function( data ) {
var name = data.find('/category[pcid = "23540"]/name');
} );
} );当然,XPath也存在于PHP中,如果您正在寻找类似的示例,请参阅此昨天的回答。
相关信息:
https://stackoverflow.com/questions/10395251
复制相似问题