I want to parse this RSS without Php:

<rss version="2.0">
  <channel>
    <item>
       <title>Test</title>
       <link>http://www.test.com</link>
       <image>
          <url>http://foo.bar/test.jpg</url>
       </image>
       <description>
       <![CDATA[Description text here!<br><a href="http://www.test.se" target="_blank" rel="external" data-ajax="false">Link!</a></div>]]>
       </description>
    </item>
  </channel>
</rss>

Can I accomplish this without Php? I'm a complete newbie in jQuery/javascript.. The XML is here: http://hundkartan.se/karta/kartdata/cron_webbutiker_mob.xml

I'm going to use this in phonegap so it's an EXTERNAL feed.

share|improve this question
Did you try anything yet, or you expecting to be new to JavaScript forever? – Grant Thomas Apr 5 at 8:31
I've tried several javascripts that I've found with some googleing. None of them has worked yet :/ – Hundkartan Jonas Apr 5 at 8:34
jquery: api.jquery.com/jQuery.parseXML – matpol Apr 5 at 8:36
possible duplicate of Parsing XML / RSS from URL using Java Script – Quentin Apr 5 at 8:36

1 Answer

up vote 1 down vote accepted

My advice is to use json with javascript. You can convert the XML into a json file with some external script (like this XML2JSON).

JSON is natively supported by javascript so access to a member is really simple. For example to obtain all link you can simply do:

<head>
    <script type="text/javascript" src="xml2json.js"></script>
    ...
</head>
...

<body> 
    <script>
    var json = xml2json.parser(XML_file);
    var channel = json.rss.channel;
    var links = [];
    for(var i = 0; i < channel.item.length; i++)
        links.push(channel.item[i].link);
    ...
    </script>
    ...
</body>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.