<?xml version="1.0" encoding="UTF-8"?>
<!-- xml提示:禁止添加任何@或者#的字符 -->
<student>
<UserId txt_s ="用户的Id">01</UserId>
<Name txt_s ="用户的姓名">张三</Name>
</student>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
window.οnlοad= function(){
$.ajax({
url: 'Test.xml',
type: 'GET',
dataType: 'xml',
timeout: 1000, //设定超时
cache: false, //禁用缓存
error: function(xml) {
alert("加载XML文档出错!");
},
success: GetStudentComplete //设置成功后回调函数
}); }
//获取XML成功后回调函数
function GetStudentComplete(xml) {
$(xml).find("student").each(function(i) { //查找所有student节点并遍历
var id = $(this).children("UserId"); //获得子节点
// console.log("节点"+id);
var id2 = $(this).children("UserId").attr("txt_s");
var id_vaule = id.text(); //获取节点文本
console.log("student 节点下 userid的内容"+id_vaule +" userid的txt_s 属性"+id2);
});
}
</script>
</head>
<body>
</body>
</html>