简体   繁体   English

使用jQuery的XML与HTML

[英]HTML with XML using jQuery

i have xml file which contains lots of data. 我有包含大量数据的xml文件。 now i want to pick a price with some condition. 现在我想选择某种条件下的价格。 i set a parameteres in javascript function but it is not giving desire result. 我在javascript函数中设置了一个参数,但是没有给出期望的结果。 i think it can be done through childnode but i didnot aware about that 我认为可以通过childnode完成,但是我不知道

XML file XML文件

<flights updated="2012-03-09T04:38:00.437" type="flights" ob_id="45792117" lastedit="2012-03-09T15:10:01" partner_id="63" activate_date="2012-02-15T00:00:00" page_id="9646" page_pk_id="12597" pos_pk_id="51565" pos="1" module_id="3" pos_name="Flights" product_type_id="4" product_type="flight" headline="Bali" destination="Bali" localised_destination="Denpasar" headline_no_html="Bali" price="199" deals_space_limited="0" deals_sold_out="0" qa_approved="1" tp_available="0" tp_weight="10" partner_eapid="0-25" partner_pid="25" publish_path="\\dubvappdaily01\daily_aus\data\psf\" partner_lang_id="3081"  FrTLAs="PER" ToTLAs="DPS" FrDate="2012-04-27T00:00:00" ToDate="2012-05-04T00:00:00" Airline="QZ"/>

<flights updated="2012-03-09T04:38:00.437" type="flights" ob_id="45792117" lastedit="2012-03-09T15:10:01" partner_id="63" activate_date="2012-02-15T00:00:00" page_id="9646" page_pk_id="12597" pos_pk_id="51565" pos="1" module_id="3" pos_name="Flights" product_type_id="4" product_type="flight" headline="Bali" destination="Bali" localised_destination="Denpasar" headline_no_html="Bali" price="199" deals_space_limited="0" deals_sold_out="0" qa_approved="1" tp_available="0" tp_weight="10" partner_eapid="0-25" partner_pid="25" publish_path="\\dubvappdaily01\daily_aus\data\psf\" partner_lang_id="3081"  FrTLAs="SYD" ToTLAs="DPS" FrDate="2012-04-27T00:00:00" ToDate="2012-05-04T00:00:00" Airline="QZ"/>

HTML page HTML页面

<head>
  <script type="text/javascript">

    function myXml(origin, destination ) {
      var x = xmlDoc.getElementsByTagName("flights");

      for(i=0; i<x.length; i++) {
          if (x[i].getAttribute('FrTLAs') == origin
           && x[i].getAttribute('destination') == destination) {
              alert(x[i].getAttribute('price'))
          }
      }
    }
  </script>
</head>

<body>
  <a href="#" onclick="myXml('SYD','Bali')">click me</a>
</body>

did u miss this?? 你错过了吗?

xmlDoc=loadXMLDoc("flights.xml");

chk this page chk此页面

http://www.w3schools.com/dom/prop_element_attributes.asp

the example2 is very clear how to use this example2非常清楚如何使用它

x=xmlDoc.getElementsByTagName("book")[0].attributes;
   //here its would be getElementsByTagName("flights") in the loop
   //then .attributes on it
   // and then this
frtlas=x.getNamedItem("FrTLAs");
desti=x.getNamedItem("destination");

//and your code here

hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM