×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Read local xml file

    Hello everyone,
    excuse my bad English,
    I can not read the files locally.
    If the XML file I put it on the internet everything works perfectly.
    Can you help me please?
    I tried in every way but nothing.

    Code:
    $.ajax({
    		type: "GET",
    		url: "xml/settings.xml",
    		dataType: "xml",
    		success: function(xml) {
    			$(xml).find('setting').each(function(){
    			var city = $(this).find("city").text();
    			var link = $(this).find("link").text();
    			$('#city span').append(city);
    			});
    		}
    	});
    I thank everyone in advance.
    regards

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Re: Read local xml file

    I have tried in this way but does not work anyway.

    Code:
    var xmlhttp;
    
    	xmlhttp = null;
    	if (window.XMLHttpRequest) {// code for IE7, Firefox, Mozilla, etc.
    		xmlhttp = new XMLHttpRequest();
    	}
    	else 
    		if (window.ActiveXObject) {// code for IE5, IE6
    			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    		}
    	if (xmlhttp != null) {
    		var httpReq = null;
    		httpReq = new XMLHttpRequest();
    		
    		// Enable universal browser read
    		try{ 
    			netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); 
    		}
    		catch(e){ } 
    	
    		httpReq.open("GET", "xml/settings.xml", true);
    		httpReq.send(null);
    		
    		httpReq.onreadystatechange = function(){//Call a function when the state changes.
    			if (httpReq.readyState == 4) {
    				if (httpReq.status == 200) {
    					//Do something with the returned xml
    					
    					var yourResponseXML = httpReq.responseXML;
    					var nodes = yourResponseXML.getElementsByTagName('setting');
    					
    					for (var i = 0; i < nodes.length; i++) {
    						var codeAttribute = nodes[i].attributes.getNamedItem('city').nodeValue;
    						document.getElementById('city').innerHTML = codeAttribute;
    					}
    					
    					
    				}
    				else {
    					alert("Error - Server May be Down");
    				}
    			}
    		}
    	}
    	else {
    		alert("Your browser does not support XMLHTTP.");
    	}
    always return "Error - Server May be Down".

    I trust in your help!

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    8

    Re: Read local xml file

    as long as the file is not too big, why not have the widget download the file from internet on first load and save with preferenceForKey.

    I am doing this now, albeit not with xml since there was a little much overhead. i am storing a a database locally in widget with preferenceForKey entries setup from a request to server for a page and parsing response text.

    I am using somewhat like a csv format but with additional sectional separator codes for different sections of data. I found the split() function was much faster than xml parsing or JSON.parse and like I said above the download overhead size was about half as well

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Re: Read local xml file

    Thank you for responding.
    I dont think depends on the size of the file.
    does not work either with a file like this

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <setting>
    <city id="city">Rome</city>
    </setting>

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    8

    Re: Read local xml file

    not sure about use with a LOCAL file, but if you look at the RSS example widget, ajax calls definitely work OK.

    i just reused a lot of that code for my request

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Re: Read local xml file

    Not work for me.
    Any suggestions?
    Thanks

  7. #7
    Nokia Developer Expert
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: Read local xml file

    Hello,

    I have reported this behavior to our browser folks for further investigation.

    Ilkka - FN

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    5

    Re: Read local xml file

    some news about?
    thanks!

  9. #9
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Read local xml file

    Hi mic3000,

    as long as you have to integrate local data inside a WRT widget, you could think about using the JSON format instead of XML, since it save you the need to perform the loading and parsing operations.

    Pit

Similar Threads

  1. How to read XML file from Web
    By satheeshmd in forum [Archived] Flash Lite on Nokia Devices
    Replies: 1
    Last Post: 2009-02-09, 18:29
  2. widget using local xml file
    By swetha_t in forum Symbian
    Replies: 3
    Last Post: 2008-05-30, 15:26
  3. Replies: 0
    Last Post: 2007-10-11, 09:19
  4. write and read a TInt data from the file
    By billqu in forum Symbian
    Replies: 2
    Last Post: 2004-12-27, 15:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×