xml文档
<?xml version="1.0" encoding="utf-8" ?>
<root>
<info name="lee">hehe</info>
<info name="joky">haha</info>
<employes>
<employe name="wowo">可爱</employe>
<employe name="aa">机灵</employe>
</employes>
</root>
jquery 代码
首先引入jquery.js库
$.get("xml.xml",function(xml){
var infos=$(xml).find("info");
var employes=$(xml).find("employe");
alert(infos.length);//总共找到多少条数据
alert(infos.eq(0).attr("name"));//得到第一条记录的name属性值
alert(infos.eq(0).text());//得到第一条记录的文本值
alert(infos.last().text());//得到最后一条记录的文本值
alert($(infos).filter(
function(i){
var s=$(this).attr("name")=='lee'?this:null;
return s;
}
).text());//得到name 为lee 的标签的文本
alert($(infos).map(function(){
return $(this).text();
}).get().join(","));//将一组元素转换成其他数组
});