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.
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");
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!