weixin_33701251 2011-05-25 10:54 采纳率: 0%
浏览 23

重复的Jquery XML解析

Struggling to figure this out.

I've got an XML file that I call with ajax, then I need to set the element text as variables.

Two of the elements have the same name, and I don't know how to get them separately:

<myElement>

    <Country>
       <Id>1</Id>
       <CountryCode>UK</CountryCode>
       **<Name>United Kingdom</Name>**
    </Country>

    <County>
       <Id>7</Id>
       **<Name>West Midlands</Name>**
    </County>

</myElement>

This is how I currently get them:

    $(results).find("myElement").each(function (i, item) {
        var countryName = $(this).find('Name').text();
        var countyName = **$(this).find(' ???? ').text();** 

    });

Not come across this before, but the XML file ISN'T mine so I can't just rename the elements.

  • 写回答

2条回答 默认 最新

  • 妄徒之命 2011-05-25 11:43
    关注

    Well, your county is outside of your country tag, so therefore you'd have to do something like this for that line.

    $('County', results).children('Name').each(function(){
      countyName = $(this).text();
    });
    

    This link further expands upon the above code, and describes it a bit more fully.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型