Replace a Partial URL in a RSS feed

You must Login before you can answer or comment on any questions.

I need some suggestion on how I would dynamically replace part of a URL in a RSS feed. In the RSS example in Kitchen sink it is using CNN.

Here is the KS sample code. // Podcast mp3 enclosure mp3_url = itemList.item(c).getElementsByTagName("enclosure").item(0).getAttribute("url");

That code reads this line in the XML file "enclosure url="http://rss.cnn.com/~r/services/podcasting/newscast/rss/~5/rlIIrErHkQA/CNN-News-10-20-10-10AM.mp3" length="1044565" type="audio/mpeg""

So my question is how would I replace CNN.com portion or the url with another URL say FOX.com

Example http://rss.cnn.com/~r/services/podcasting/newscast/rss/~5/rlIIrErHkQA/CNN-News-10-20-10-10AM.mp3

Needs to be http://rss.FOX.com/~r/services/podcasting/newscast/rss/~5/rlIIrErHkQA/CNN-News-10-20-10-10AM.mp3

I know that URL won’t actually work in the real world, It is just an example of what I need done.

— asked 3 years ago by David Q
0 Comments

2 Answers

You could do a string replace like:

var url = "http://rss.cnn.com/~r/services/podcasting/newscast/rss/~5/rlIIrErHkQA/CNN-News-10-20-10-10AM.mp3";
 
url = url.replace("rss.cnn.com", "rss.fox.com");

— answered 3 years ago by Chris Schultz
answer permalink
1 Comment
  • I've tried the standard javascript replace for escaping strings in a url:

    wurl = wurl.replace("\"","%20");

    and it works- the string gets replaced, but Titanium gives me an error:

    [ERROR] Script Error = Result of expression 'wgeturl' [undefined] is not an object

    — commented 2 years ago by Richard John

I have tried that already and it didn’t work. The URL is defined in the xml/RSS and changes with every post. The URL is not static, this would work on a static url but not a dynamic URL.

Your Answer

Think you can help? Login to answer this question!