<!--载入jquery-->
<
script
src
=
"http://code.jquery.com/jquery-1.8.3.min.js"
></
script
>
<
script
>
var str ='<
Layer
><
Feature
id
=
"1"
><
Attribute
value
=
"XXX小区"
name
=
"xmmc"
/><
Attribute
value
=
"2008-074"
name
=
"xmbh"
/><
Attribute
value
=
"16750"
name
=
"jzmj"
/></
Feature
><
Feature
id
=
"473"
><
Attribute
value
=
"XX小区"
name
=
"xmmc"
/><
Attribute
value
=
"2006-057"
name
=
"xmbh"
/><
Attribute
value
=
"17749"
name
=
"jzmj"
/></
Feature
></
Layer
>';
try {
var xmlDom=$.parseXML(str);//将xml解析为js DOM对象
var xmbhObj=$(xmlDom).find('[name=xmbh]');//获取对象中的所有name属性值为xmbh的元素对象(可能有多个)
xmbhObj.each(function(){//循环遍历获取到的元素对象
var value=$(this).attr('value');//获取当前元素对象中的value属性值
alert(value);//弹出一下
});
} catch(ex) {
alert('无法解析的xml')
}
</
script
>
转载自:https://zhidao.baidu.com/question/584666985701586925.html