Plz在我的xml下面看到,我试图用jquery
解析它XML
<atom:entry>
<atom:id>Alex Kane</atom:id>
<atom:title type="text/html">Alex Kane</atom:title>
<wplc:field id="gender">MALE</wplc:field>
<wplc:field id="doc_source">default</wplc:field>
<wplc:field id="degree">M.D.</wplc:field>
<wplc:field id="defaultcontext">/poc</wplc:field>
<wplc:field id="docid">Alex Kane</wplc:field>
<wplc:field id="title">Alex Kane</wplc:field>
<wplc:field id="language">English</wplc:field>
<wplc:field id="doctortype">Plastic Surgery</wplc:field>
<wplc:field id="condition">3D Surface Motion Capture</wplc:field>
<wplc:field id="condition"></wplc:field>
<wplc:field id="condition">Kinematic Motion Capture</wplc:field>
<wplc:field id="condition">Cleft Lip</wplc:field>
<wplc:field id="condition">Cleft Palate</wplc:field>
<wplc:field id="condition">Velocardiofacial Syndrome</wplc:field>
</atom:entry>
JQUERY
success : function(data){
$(data).find('atom\\:entry, entry').each(function(){
$(this).find('wplc\\:field, field').each(function(){
if($(this).attr('id') == "condition"){
}
});
});
}
});
这里我试图获得标题(Alex Kane),其中id =“condition”为空。 我怎么能实现这个?
答案 0 :(得分:0)
这样的事情应该让你开始。
foo: { bar_ids: [""] }
请注意,由于没有xml命名空间定义,以下演示稍微修改了标记名称($(data).find('atom\\:entry').each(function(){
// collection of "conditions"
var $conditions = $(this).find('wplc\\:field[id="condition"]');
// filter empty conditions and get length
var hasEmptyCondition = $conditions.filter(function(){
return !$.trim($(this).text())
}).length;
var emptyName
if(hasEmptyCondition){
emptyName = $(this).find('wplc\\:field[id="title"]').text();
alert(emptyName +' has empty condition')
}
});
已更改为:
)
的 DEMO 强>
答案 1 :(得分:0)