0

i have xml file which contains lots of data. now i want to pick a price with some condition. i set a parameteres in javascript function but it is not giving desire result. i think it can be done through childnode but i didnot aware about that

XML file

<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

<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>
0

1 Answer 1

1

did u miss this??

xmlDoc=loadXMLDoc("flights.xml");

chk this page

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

the example2 is very clear how to use this

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.