Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User renjini's Avatar
    Join Date
    Mar 2011
    Posts
    5
    Hi,

    I was trying to parse an xml file in Web apps. USing DOM parser it is working fine on wrt, but it is not working on s40 web apps.

    I response is received when xhr.responseText is used. But xhr.responseXML is not responding anything (ie, null)

    I also tried XML tag reading using xhr.responseXML.getElementsByTagName("companyName"); in s40 web apps, but not responding (ie, null).

    Is there any solution ? Is there any other effective XML parser available for S40 Web apps.

    code snippets are

    function init()
    {

    getRSS(url);

    }




    function getRSS()
    {
    var xhr;
    rssfeed = url;

    //call the right constructor for the browser being used
    if (window.ActiveXObject)
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
    else
    if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();

    }
    else
    alert("AJAX request not supported");

    //prepare the xmlhttprequest object
    xhr.open("GET", rssfeed, true);
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Pragma", "no-cache");
    xhr.onreadystatechange = function(){

    if (xhr.readyState == 4) {
    if (xhr.status == 200) {

    if (xhr.responseText != null) {

    var company = xhr.responseXML.getElementsByTagName("companyName");

    alert("name1::"+company[0].childNodes[0].nodeValue);

    }
    else {


    //return false;
    }
    }
    else {


    }
    }
    }


    //send the request
    xhr.send(null);

    }

  2. #2
    Nokia Developer Moderator isalento's Avatar
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    831
    Hi,

    I hope that you got this working already. I have completely missed this thread previously, sorry for that.
    Basically the script you have should work. Only changes needed is to check for responseXML instead of responseText and remove alert(). Alert() does not work in Series 40 web apps.

    If you are generating the xml by yourself in your server, check that you set proper content type:
    header("Content-type: text/xml"); (PHP way)

    Br,
    Ilkka

  3. #3
    Registered User ciebal's Avatar
    Join Date
    Nov 2011
    Location
    Behind Proxy
    Posts
    5
    you can use it for parsing xml for s40 :

    Code:
    $(document).ready(function () {
        jQuery.support.cors = true;
    	   $.ajaxSetup({
    			error:function(x,e){
    				if(x.status==0){
    				alert('You are offline!!\n Please Check Your Network.');
    				window.location = 'index.html';
    				}else if(x.status==404){
    				alert('Requested URL not found.');
    				window.location = 'index.html';
    				}else if(x.status==500){
    				alert('Internel Server Error.');
    				window.location = 'index.html';
    				}else if(e=='parsererror'){
    				alert('Error.\nParsing JSON Request failed.');
    				window.location = 'index.html';
    				}else if(e=='timeout'){
    				alert('Request Time out.');
    				window.location = 'index.html';
    				}else {
    				alert('Unknow Error.\n'+x.responseText);
    				window.location = 'index.html';
    				}
    			}
    		});
        $.ajax({
            type: "GET",
            url: "http://data.bmkg.go.id/lastgempadirasakan.xml",
            crossDomain: true,
            dataType: "xml",
            success: xmlParser
        });
    });
    function xmlParser(xml) {
        $('#load').fadeOut();
    
     	$(xml).find("Gempa").each(function () {
            $(".main").append('<center><b>Terjadi Gempa Dirasakan ' + $(this).find("Magnitude").text() + ' </b></center><br>Tanggal : ' + $(this).find("Tanggal").text() + ' <br> Waktu : ' + $(this).find("Jam").text() + '<br>' + $(this).find("Keterangan").text() + ', dirasakan di ' + $(this).find("Dirasakan").text() + '');
            $(".bmkg").fadeIn(1000);
    	});
    }
    Replace xml url : http://data.bmkg.go.id/lastgempadirasakan.xml with your xml. And note the structure of the xml.
    Edit this part :
    Code:
    function xmlParser(xml) {
        $('#load').fadeOut();
    
     	$(xml).find("Gempa").each(function () {
            $(".main").append('<center><b>Terjadi Gempa Dirasakan ' + $(this).find("Magnitude").text() + ' </b></center><br>Tanggal : ' + $(this).find("Tanggal").text() + ' <br> Waktu : ' + $(this).find("Jam").text() + '<br>' + $(this).find("Keterangan").text() + ', dirasakan di ' + $(this).find("Dirasakan").text() + '');
            $(".bmkg").fadeIn(1000);
    	});
    }
    CMIIW
    Nokia Student Developer | Microsoft Student Partner
    - http://about.me/ciebal

Similar Threads

  1. How to Call Soap service in S40 web apps
    By monima in forum Nokia Asha Web Apps
    Replies: 9
    Last Post: 2012-01-03, 09:51
  2. S40 Web Apps
    By simonB in forum Nokia Asha Web Apps
    Replies: 1
    Last Post: 2011-07-05, 09:33
  3. Replies: 12
    Last Post: 2010-03-21, 19:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved