473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

RSS as js variable

Hi All,
I was playing with the idea of getting an RSS feed as js
variable from one server http://www.geocities.com/sly_i/rssvar.js and
then parsing it via js on another server
http://www.myjavaserver.com/~slyi/myrss.htm. But i cant find any site
that provide the raw RSS as a js variable.

I asked the guys who make the great feed2js
http://jade.mcli.dist.maricopa.edu/feed/ but they dont believe the idea
of providing rss in a raw format in worth pursuing.

Do you know of any site that would provide this?
I dont mind if it contains google ads as long as you can specify the
rss url and recieve it as a js variable.

thanks for your help

slyi

Jul 23 '05 #1
3 1615
fox


slyi wrote:
Hi All,
I was playing with the idea of getting an RSS feed as js
variable from one server http://www.geocities.com/sly_i/rssvar.js and
then parsing it via js on another server
http://www.myjavaserver.com/~slyi/myrss.htm. But i cant find any site
that provide the raw RSS as a js variable.

I asked the guys who make the great feed2js
http://jade.mcli.dist.maricopa.edu/feed/ but they dont believe the idea
of providing rss in a raw format in worth pursuing.
there's no real advantage... many newer mail and news clients will read
rss files.

If you want the feeds available to JS for development purposes, with a
very little bit of help from php you can simply:
<offtopic>

<?php //4.30 or better

if(isset($_REQUEST) && isset($_REQUEST["url"]))
{
$contents = file_get_contents($url);

// remove all return and linefeed characters!
$contents = preg_replace("/\r|\f/","",$contents);

}
?>

<script ...>

// convert newlines to literal \n so they can be restored
// and add slashes to quotes
var rss = "<?=addslashes(preg_replace("/\n/","\\n",$contents));?>";

.....

</script>

If you do not need to preserve newlines, then you can remove them with
the returns and linefeeds (regex: "/\n|\r|\f/") and simply use
<?=addslashes($contents);?> above. However, you might find it easier if
the rss is broken down into chunks (you can rss.split("\\n")...). For
displaying in the textarea, i used rss.split("\\n").join("\n");

This script gets into serious trouble very quickly if the content is not
rss/xml... your script should control which feeds are available to the user.

I have an example at:
http://fxmahoney.com/demo/rss_to_js....s/nyt/Arts.xml

[if your reader wraps lines -- make sure you copy and paste the entire
url in the location bar]

it loads the contents of the rss/xml into a javascript variable which is
loaded into a form textarea upon onload. (View Source)

As far as i can tell, RSS 2.0 (0.91 tested also) feeds should do well
enough with this script. HTML will not!! [not ANY site i tested]

If all you have access to is php 3.x, I don't think you'll be able to do
this (fopen_wrappers required) -- if php >=4.0 and < 4.3, then use:

if($f = fopen($url, "r"))
{
while(!feof($f))
$contents .= fread($f, 8192);

fclose($f);
}
</offtopic>
Do you know of any site that would provide this?
I dont mind if it contains google ads as long as you can specify the
rss url and recieve it as a js variable.
.... bandwidth issues ... better to do it yourself
thanks for your help

slyi

Jul 23 '05 #2
Thanks fox. Your answer was most useful, i do know a bit of php and
have the server access
But i was hoping that someone knew of a service available on the web
for this
As this could be a workaround for the x-site scripting restrictions
client side RSS.

Jul 23 '05 #3
fox


slyi wrote:
Thanks fox. Your answer was most useful, i do know a bit of php and
have the server access
But i was hoping that someone knew of a service available on the web
for this
As this could be a workaround for the x-site scripting restrictions
client side RSS.


if you have the bandwidth for it -- or want to get involved in
"subscriptions" for the service (or free if the demand is not high),
then the easiest thing to do is use the php to generate a *.js file from
the rss feed as illustrated.

One way is to set *.js files to be pre-processed by php by adding the
file type to .htaccess:

AddType application/x-httpd-php .js

users would directly access the php disguised as js served from your domain.

[**i'm pretty sure you can simply use <script src=myscript.php... just
as easily without messing with htaccess]

<script
src="http://yourdomain.com/scripts/rss.js?feed=http://somedomain.com/rss.xml"
type=text/javascript></script>

//-------rss.js:

<?

if(isset($_REQUEST) && isset($_REQUEST["feed"]))
{
$contents = file_get_contents($feed);
$contents = preg_replace("/\r|\f/","",$contents);
}

?>

var rss = "<?=addslashes(preg_replace("/\n/","\\n",$contents));?>";

// -------end rss.js

[ a lot of people don't realize that .js files can be passed
location.search (aka, GET) data just like any other URL ]

Add some parsing functions and your ready to serve RSS via JS yourself.
I'm not familiar with x-site, so I really couldn't make any further
recommendations about possible workarounds.

fox
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Scott | last post by:
I have an XML Document in a format like: <Variable name="Bob">ABCDEFG</Variable> <Variable name="Steve">QWERTYUI</Variable> <Variable name="John">POIUYTR</Variable> <Variable...
4
by: Frederik Sørensen | last post by:
I include a xslt stylesheet with variables for all the error messages in my system. <xsl:variable name="Banner_error_1"> errormessage 1 for banner </xsl:variable> <xsl:variable...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
10
by: Blaxer | last post by:
There is probably a really easy way to do this, so please forgive me but I would like to set the value of a variable from a variable, an example would be... function Calculate_Something(ByVal...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
3
by: rls03 | last post by:
I have the following which creates a variable containing a relative path where <xsl:value-of select="."/returns a portion of the filename: <xsl:variable...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
2
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.