如何显示XML文件的列表格式数据?

时间:2010-01-28 07:54:01

标签: jquery xml

我遇到了jQuery和XML的问题。 我正在使用jQuery从XML文件加载数据。它工作正常 但我想显示数据跟随列表格式及其标题,当我点击标题时,它的信息将显示。 我该怎么办?

我的代码:

$(document).ready(function(){
    $.ajax({
    type: "GET",
    url: "xml/tuyendung.xml",
    dataType: ($.browser.msie) ? "text" : "xml",
    success: function(xml) {

        var newXML = parseXml(xml);


        $(newXML).find('TDDetail').each(function(){

            var emailid = $(this).attr('email');
            var tdcode = $(this).attr('tdcode');
            var title = $(this).find('jobtitle').text();
            var position = $(this).find('positiontitle').text();
            var jobdescribe= $(this).find('jobdescribe').text();
            var jobexperience= $(this).find('jobexperience').text();
            var jobskills= $(this).find('jobskills').text();
            var jobtime= $(this).find('jobtime').text();
            var joblocation= $(this).find('joblocation').text();
            var jobcategory= $(this).find('jobcategory').text();
            var joblevel= $(this).find('joblevel').text();
            var jobsalary= $(this).find('jobsalary').text();
            var ecount=0;
            matd=new Array();


                if($(this).attr('email')==GetCookie('Email') && tdcode==tdcode  )
                {       


                    $('<div class="items" id="link_'+tdcode+'"></div>').html('<a href="javascript:hienthi()">'+title+'</a>').appendTo('#textb');

                }                               

            });

        }
    });
});

和我的XML文件:

 <?xml version="1.0"?>
<TD>
    <TDDetail email="cspniit@gmail.com" tdcode="TD001" jobtitle="quan ly">
        <jobtitle>Quan ly</jobtitle>
        <positiontitle>Manager</positiontitle>
        <jobdescribe>Quan ly nhan su cong ty ABC</jobdescribe>
        <jobexperience>2</jobexperience>
        <jobskills>Anh van giao tiep tot. Chung chi tin hoc B</jobskills>
        <jobtime>Fulltime</jobtime>
        <joblocation>CanTho</joblocation>
        <jobcategory>IT-Software</jobcategory>
        <joblevel>Manager</joblevel>
        <jobsalary>thoa thuan</jobsalary>
    </TDDetail>
    <TDDetail email="cspniit@gmail.com" tdcode="TD002" jobtitle="quan ly ma">
        <jobtitle>Quan ly ma</jobtitle>
        <positiontitle>Manager</positiontitle>
        <jobdescribe>Quan ly nhan su cong ty ABC</jobdescribe>
        <jobexperience>2</jobexperience>
        <jobskills>Anh van giao tiep tot. Chung chi tin hoc B</jobskills>
        <jobtime>Fulltime</jobtime>
        <joblocation>CanTho</joblocation>
        <jobcategory>IT-Software</jobcategory>
        <joblevel>Manager</joblevel>
        <jobsalary>canh tranh</jobsalary>
    </TDDetail>
    <TDDetail email="aa@gmail.com" tdcode="TD003" jobtitle="giam doc">
        <jobtitle>Giam Doc Van Phong</jobtitle>
        <positiontitle>Manager</positiontitle>
        <jobdescribe>Quan ly nhan su cong ty ABC</jobdescribe>
        <jobexperience>2</jobexperience>
        <jobskills>Anh van giao tiep tot. Chung chi tin hoc B</jobskills>
        <jobtime>Fulltime</jobtime>
        <joblocation>CanTho</joblocation>
        <jobcategory>IT-Software</jobcategory>
        <joblevel>Manager</joblevel>
        <jobsalary>compete</jobsalary>
    </TDDetail>
    <TDDetail email="cspniit@gmail.com" tdcode="TD003"><jobtitle>Giao hang</jobtitle><positiontitle>employee</positiontitle><jobdescribe>Tuyen nhan vien gio hang trong noi thanh Can Tho</jobdescribe><jobexperience>0</jobexperience><jobskills>Lanh le , gioi viec</jobskills><jobtime>Parttime</jobtime><joblocation>CanTho</joblocation><jobcategory>Sale</jobcategory><joblevel>graduate</joblevel><jobsalary>thoa thuan</jobsalary></TDDetail></TD>

1 个答案:

答案 0 :(得分:0)

我认为你必须:

var newXML = parseXml(xml);

直接使用xml:

        $(xml).find(.......

修改

 /space/ <?xml version="1.0"?>

请检查<?xml ...之前是否有空格,有时可能会给IE带来错误......标记......您可以进行验证检查here