语言

Menu
Sites
Language
Parsing RSS Feed

Hello,

I am trying to parse this RSS feed: "http://www.leparisien.fr/automobile/rss.xml", I used a Parser object to parse it, the problem is it is working with the Web Simulator, but I get nothing with the emulator, although I added the following link "http://www.leparisien.fr" into the Network URl (policy tab) in the config.xml file.

What should I do?

 

响应

7 回复
Marco Buettner

Can you share your code how did you parse the xml?

I think its better to merge $.ajax with $.parseXML

function parser(data)
{
    var xml = $.parseXML(data)
    // TODO: Write your follow parsing code hier
}

$.ajax({url: "http://www.leparisien.fr/automobile/rss.xml})
    .done(
        parser
    )
    .fail(function (xhr, status, error) {
        switch(status)
        {
            case 'timeout'
                alert("timeout");
            default:
                alert("unknown error occurs");
        }
    });

 

Marco Buettner

I forgot a quote on the ajax url ;)

AVSukhov

Hello,

 

Maybe you need add "subdomains=true" to "access| element.

Mohamed Guembri

Hello, i am having the same problem in the xml parsing did you got any helpful solution? here is the code i'm using:

 

var initsamsung = function () {
    // TODO:: Do your initialization job
    console.log("init() called");
 
    alert("alert1");
    if ( ParserSamsung.initsamsung()) {
          alert("alert2");
        ParserSamsung.DatasamsungReceivedCallback = function() {
		var i; 
  	

		  alert("alert3");
		 
		 
		    for(i=0; i<Datasamsung.getNomCount(); i++){
		    
		    	var div = document.createElement("div");
		    	
		    	  alert(Datasamsung.getNom(0));

          
		    	  div.innerHTML='<div class="info-box"> <div class="info-box"><span class="info-box-icon bg-aqua"><img src="http://'+Datasamsung.getimage1(i)+'"  width="90x" height="80px"></a></span><div class="info-box-content"><span class="info-box-text">'+Datasamsung.getNom(i)+'</span><span class="info-box-number"><small></small></span></div><!-- /.info-box-content --></div><!-- /.info-box --></div><!-- /.col -->';
 
				    alert(Datasamsung.getimage1(i))
				    document.getElementById("listesamsung").appendChild(div);  
				    }
				 
				  
				  
				    
		        };
		      
		        ParserSamsung.fetchDatasamsung(); 
				
		    }
		    else {
		       
		    }





		};
		$(document).bind('pageinit', initsamsung);

on the Simulator the two first alerts are working, the problem starts with the third one which  weirdly, works perfectly on the simulator

Marco Buettner

Did you get any error on the web console on chrome?

Mohamed Guembri

No I didn't.

I found a solution which is to eliminate the CDATA from the xml that I want to parse.

This is the previous xml link: http://khaledmobileapps.esy.es/item.xml
and this is the modified one:  http://khaledmobileapps.esy.es/phones.xml

Hope it's helpful.

Seoghyun Kang

Hello.

Please refer the following code in the NewsFeed sample. You can find the way to parse the XML file.

xmlhttp = new XMLHttpRequest();
xmlhttp.open(XML_METHOD, XML_ADDRESS, false);
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState === 4) {
        if (xmlhttp.status === 200) {
            clearElmText(objNews);

            xmlDoc = xmlhttp.responseXML;
            dataItem = xmlDoc.getElementsByTagName('item');

            if (dataItem.length > 0) {
                // TODO
            } else {
                // TODO
            }

            xmlhttp = null;
        }
    }
};

xmlhttp.send();