用jquery获取xml页面 以json字符串格式输出

//xml.xml页面

<div>
    <div>
        <aaaa>zhangsan'saaaa>
        <bbbb>manbbbb>
    div>
    <div>
        <aaaa>lisi <zhangsan aaaa>
        <bbbb>womanbbbb>
    div>
div>

//jquery页面
<script src="jquery-1.7.2.min.js">script>
<script type="text/javascript">
    $(function(){
        $.post("xml.xml",function(msg){
            var _name = $(msg).find("aaaa");
            var _sex = $(msg).find("bbbb");
            str = '[';
            for(var i=0;i<_name.size();i++){
                str += "{name:'"+_name.eq(i).text()+"',sex:'"+_sex.eq(i).text()+"'}";
            }
            str += "]";
            str = str.replace("<","<");
            document.write(str);
        }, 'xml');
    })
script>


你可能感兴趣的:(用jquery获取xml页面 以json字符串格式输出)