【发布时间】:2017-12-04 08:57:54
【问题描述】:
我正在尝试使用 jquery 过滤功能并解析 XML,但遇到了问题。 我的 XML 如下所示:
<root>
<data name="0121C395-AFCE-49C8-A163-55E24325D691" xml:space="preserve">
<value>Report an incident</value>
</data>
<data name="0121C395-AFCE-49C8-A163-55E24325D691_descr" xml:space="preserve">
<value>In this service it's possible to report incidents.</value>
</data>
<data name="0121C395-AFCE-49C8-A163-55E24325D691_short" xml:space="preserve">
<value>Report Incident</value>
</data>
</root>
我的 Jquery 看起来像这样:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://localhost/servicemarket/ReachOut/Services.xml",
dataType: "xml",
success: function(xml){
var dataVal = $(xml).find('data').filter(function(){
return $('data', this).attr('name') == '0121C395-AFCE-49C8-A163-55E24325D691';
});
dataVal.each(function(index, data){
console.log($(data).find('value').text());
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});
我的目标是根据传入的数据属性获取节点值。 非常感谢所有帮助! :) 谢谢!!
【问题讨论】: