XML DOM遍历Jquery [英] XML DOM traversing with Jquery

查看:91
本文介绍了XML DOM遍历Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

尝试使用jquery解析xml。

这似乎只适用于IE 11(没有尝试旧版本)。 Chrome,Opera和Firefox不做任何事情..

Hi guys!
Trying to parse an xml using jquery.
This seems to work only With IE 11 (didn't try older releases). Chrome, Opera and Firefox don't do anything..

<script type="text/javascript">
      if (window.XMLHttpRequest)
      {
        xmlHttp = new XMLHttpRequest();
      }
      else
      {
        xmlHttp = new ActiveXObject("Microsoft.XmlHTTP");
      }
      xmlHttp.open("GET", "DataSources/XML/XMLCountries.XML", false);
      xmlHttp.send();
      xmlDoc = xmlHttp.responseXML;
      var $xml = $(xmlDoc);
      $xml.find('Country').each(function () {
        alert($(this).attr('Name'));
      });
    </script>



这是XML文件:


This is the XML file:

<?xml version="1.0" encoding="utf-8"?>
<CountriesList xmlns="XMLCountries.xsd">
  <Country Name="England" NavigateUrl="" ImageUrl="~/Images/flags/shiny/16/England.png" Tooltip="English Leagues and Cups"/>
  <Country Name="France" NavigateUrl="" ImageUrl="~/Images/flags/shiny/16/France.png" Tooltip="French Leagues and Cups"/>
  <Country Name="Germany" NavigateUrl="" ImageUrl="~/Images/flags/shiny/16/Germany.png" Tooltip="German Leagues and Cups"/>
  <Country Name="Italy" NavigateUrl="" ImageUrl="~/Images/flags/shiny/16/Italy.png" Tooltip="German Leagues and Cups"/>
  <Country Name="Spain" NavigateUrl="" ImageUrl="~/Images/flags/shiny/16/Spain.png" Tooltip="Spanish Leagues and Cups"/>
  <Country Name="Portugal" NavigateUrl="" ImageUrl="~/Images/flags/shiny/16/Portugal.png" Tooltip="Portugal Leagues and Cups"/>
</CountriesList>



我错过了什么?我非常确定IE 11使用XMLHttprequest代替Microsoft.XMLHttp,所以这不应该是XMLHttprequest的问题。

Thx求助!


What am I missing?? I'm quite sure IE 11 uses XMLHttprequest in place of Microsoft.XMLHttp, so this shouldn't be an issue of the XMLHttprequest.
Thx for your help!

推荐答案

xml =


(xmlDoc);


xml.find('Country')。each(function() {
alert(
xml.find('Country').each(function () { alert(


这篇关于XML DOM遍历Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆