Html5 Tutorial - Future Technology

Tuesday, 25 June 2013

PhoneGap Tutorial - Parsing xml file using javascipt and displaying the data on the android and ios mobile screens

Title : I am going to explain u how to parse xml file and display data on your mobile screen.

Description : In today's world every business application need to contact webservices or xml services or xml files in the server and parse the files and need to display some results on the screen.for example take a live cricket score card : in the server we write a program where the score will be updated ball by ball,run by run in the web service , and the xml file also get updated with the live score and now the our application screen should also contact the webservice every 5 seconds and parse xml file and will update the live score for us , I will explain this with source code latter , for now i will explain you a simple example.

Here is the xml file which we are going to parse.
    
    
        MakeMyTrip.com
        MakeMyTrip.com is one of the good website providing Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/makemytrip-logo.jpg
    
    
        GoIbibo.com
        GoIbibo.com is one of the good website providing Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/goibibo_logo.png
    
    
        Abhibus.com
        Abhibus.com is one of the good website providing Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/abhibus-logo.png
    
    
        Travelyaari.com
        Travelyaari.com is one of the good website providing Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/travelyaari-com-logo-w240.png
    
    
        Redbus.in
        Redbus.com is one of the good website providing Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/logo_bc9228d_163.jpg
    
    
        Expedia.co.in
        Expedia.co.in is one of the good website providing Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/expedia-logo.png
    
    
        Other websites
        We Provide more websites that offer good Travel services to book oonline Flight,Hotel,Train and Bus tickets with guranteed lowest prices and provides new deals , offers and discount coupons every week and help you save money upto 20% while you travel.
        travellogos/travel-agency-logos.jpg
    

Now we have to parse the above file using java script and display the results using html5. Here is the html and javascript code to parse this xml file.

Javascript file

function travel(){	
	if (window.XMLHttpRequest)
	 {	// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	 }
	else
	 {	// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	 }
		xmlhttp.open("GET","Travel.xml",false);
		xmlhttp.send();
		xmlDoc=xmlhttp.responseXML;		
		travels = xmlDoc.getElementsByTagName("website");
		alert("travels:"+travels.length);
		var websites = [];
		var description = [];
		var logos = [];		
		for(var travel=0;travel

Html File



  
    
    
    Minimal AppLaud App


	  
	    

 
  
  
 
  
  
  

Coupons Shop

27 comments:

  1. Can you please show me a simple Demo of How can I Edit/Update this XML File?

    ReplyDelete
  2. Hi, I'm trying to run this example but when I copy the javascript file it seems to have an error in the 18th line.
    Could you help me please?

    Thanks a lot

    ReplyDelete
    Replies
    1. Please, share your mail id i will send you demo code.

      Delete
    2. Hey can you share the code with me too

      Delete
  3. Hi, I am facing the same problem as Marta Millan is facing. Please help me for the said.


    Thank you.

    ReplyDelete
  4. kiran_tvm@yahoo.com

    kindly send the demo code to this mail,i was facing the same problem as marta....

    ReplyDelete
  5. hi this my mail id .. sushmithabe@gmail.com please send the demo code...

    ReplyDelete
  6. hi this my mail id .. karanam.braju@gmail.com please send the demo code...

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. hi this is my mail id. loveuindia1@gmail.com please send me the demo code.thanks in advance.......

    ReplyDelete
  9. can you please send me the demo ??? miguel_martin@live.com.pt ...Thanks

    ReplyDelete
  10. hi. can you send me the the demo??
    my mail id - rupali.mandge@gmail.com
    Its somewhat urgent. Thanks

    ReplyDelete
  11. Hi, please email me the demo too.
    My email address: sambruce23@gmail.com
    Thanks.

    ReplyDelete
  12. Hey. Can u send me the demo code please?
    my e-mail is: 6rodney6@gmail.com
    Thank you.

    ReplyDelete
  13. hey can you forward your demo code to cheran030@gmail.com

    thanks

    ReplyDelete
  14. Hello, good work ! Can you send me code by email at vincenthartmann@gmail.com please ? Thanks Vincent

    ReplyDelete
  15. Hello, good work ! Can you send me code by email at prem.ce45@gmail.com please ? Thanks

    ReplyDelete
  16. good work please send me this code pwrkushal@gmail.com thanks

    ReplyDelete
  17. good one.please send me the code to this id soumya89murthy@gmail.com.Thank u

    ReplyDelete
  18. Hello, good work! Can you send me code by email at nguyenthientu95@gmail.com. Thanks

    ReplyDelete
  19. hi guys, can any one tell...
    how to call web service and how to get those response in phonegap using soap with jquery...urjent
    please send code to mail id please: vvreddy365@gmail.com

    thank you so much

    ReplyDelete