Email conversation
From | Anonymous |
To | Me |
Subject | Problems with RSS/Atom feed parser |
Date | 22 January 2007 08:47 |
Dear Mr Wilton-Jones,
I am trying to create a "rssLocal.asp" instead of the included
rsslocal.php and i think i did it, a real simple version that
is. Because now the feed parser only works in I.E. not in Firefox, Netscape
& Opera. In Opera i get the "garbage alert"
you've wrote. In Firefox and Opera nothing happens... I am not that familiar
in PHP. I do understand a lot but the PHPcode is
code is a bit complicated. If is not to much to ask can you declare the
PHPcode for me? It's a lot of replacing i think?
This is where I am at the moment:
[URL]
note: The links to [URL] don't work, this has also to do with the
localRss.asp. I think.
[URL]
if you have a look a the page source it has still got the XML standard
markup?
this the ASP code:
<%
URLToRSS = "[URL]"
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "Get",URLToRSS, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText
Response.AddHeader "Content-Type","text/xml');"
Response.AddHeader "Content-Length",len(RSSXML) & ");"
'here i need to do some replacing of some sort...
Response.write RSSXML
%>
I want to use the code to at a newsfeed to my personal site
[URL] and new to be startpage...
Furthermore I intent to at a XML feed myself of the "My personal news
database" I all ready have.
Thanks for your time.
Best regards
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 22 January 2007 09:35 |
Anonymous,
> now the feed parser only works in I.E. not in Firefox, Netscape & Opera
Works for me in Opera ... but, I think I see why:
Response.AddHeader "Content-Type","text/xml');"
Response.AddHeader "Content-Length",len(RSSXML) & ");"
Not sure why you are adding ");" on the end, but that is not a valid
header. Suspect you need this:
Response.AddHeader "Content-Type","text/xml"
Response.AddHeader "Content-Length",len(RSSXML)
> This is where I am at the moment:
Hmm, I see a problem, and I think it is my fault for not writing clear
enough instructions for modifying. You have this:
<body ...
onload="window.defVal=document.getElementById('feedcontainer').innerHTML;">
...
<script type="text/javascript">
window.onload = function () {
...
This means there are two things listening for the document's onload event.
This only works in Opera. You should remove the onload listener from the
body tag, and put that code inside the onload handler you put inside the
script.
window.onload = function () {
window.defVal=document.getElementById('feedcontainer').innerHTML;
... etc. ...
> 'here i need to do some replacing of some sort...
This section works around several bugs in various browsers. Assuming you are
not using invalid RSS 0.91, this code needs to:
Remove any XML stylesheet links that are already in the feed (otherwise some
browsers will request the broken URL, and will screw up completely if the
stylesheets are XSLT):
<?xml-stylesheet type="text/css" href="foo.css" ?>
Add a link to an empty XML stylesheet at the top (only needed to get it to
work in IE Mac):
<?xml-stylesheet type="text/css" href="empty.css" ?>
Replace all occurrences of <link ...> and </link> with <fixlink ...> and
</fixlink> respectively.
Replace all occurrences of <image ...> and </image> with <fiximage ...> and
</fiximage> respectively.
Replace all occurrences of <rss ...> and </rss> with <rssSpoof ...> and
</rssSpoof> respectively.
Replace all occurrences of <feed ...> and </feed> with <atomSpoof ...> and
</atomSpoof> respectively.
If you are using invalid RSS 0.91 (with HTML in the descriptions instead of
plain text), you also need to replace the version="0.91" attribute with
version="allowHTML91"
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 22 January 2007 13:45 |
Dear Mark,
Woooh that's a fast response! Thanks a lot!
I think I'm nearly there but it's not working yet, on a PC: Firefox and on a
Mac: Firefox and Safari the screen stays empty.
I corrected the Header mistakes. And now my ASP code creates exactly the
same XML output as your PHP code. (for
[URL])(I've put the ASPcode at bottom of this
mail) So there something with the rss.html i
think... I implemented the new load code like this:
<script type="text/javascript">
var URL = '[URL]';
window.onload = function () {
window.defVal=document.getElementById('feedcontainer').innerHTML;
importXML('rssLocal.asp?feedURL='+escape(URL),'parseRSS',false,1000);
};
</script>
Is that correct?
Kind regards
<%
' I will change this later so it will work with your <form>:
URLToRSS = "[URL]"
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "Get",URLToRSS, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText
Response.AddHeader "Content-Type","text/xml"
Response.AddHeader "Content-Length",len(RSSXML)
temp = "<?xml version="& chr(34) &"1.0"& chr(34) &" encoding="& chr(34) &
"iso-8859-1"& chr(34) &"?>"
RSSXML = replace(RSSXML,temp,"")
RSSXML = temp & vbCrLf & "<?xml-stylesheet type="& chr(34) &"text/css"&
chr(34) &" href="& chr(34) &"empty.css"& chr(34) &
"?>" & vbCrLf & RSSXML
RSSXML = Replace(RSSXML,"<link>","<fixlink>")
RSSXML = Replace(RSSXML,"</link>","</fixlink>")
RSSXML = Replace(RSSXML,"<image>","<fiximage>")
RSSXML = Replace(RSSXML,"</image>","</fiximage>")
RSSXML = Replace(RSSXML,"<rss ","<rssSpoof ")
RSSXML = Replace(RSSXML,"</rss>","</rssSpoof>")
RSSXML = Replace(RSSXML,"<feed>","<atomSpoof>")
RSSXML = Replace(RSSXML,"</feed>","</atomSpoof>")
RSSXML = Replace(RSSXML,"version=& chr(34) &0.91& chr(34) & ",
"version=& chr(34) &allowHTML91& chr(34) &")
response.write RSSXML
%>
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 23 January 2007 08:55 |
Anonymous,
> the screen stays empty.
According to Opera's error console, on line 52 (line 46 of the script
itself), you are missing the // at the start of the line (it is supposed to
be a comment):
check if the browser interpreted the XML correctly
should be:
//check if the browser interpreted the XML correctly
(It also shows a couple of CSS errors, but these are not the cause of the
problem.)
Tarquin
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 23 January 2007 09:23 |
I did some tests yesterday and tried to skip the parseRSS but that didn't
help. I removed all the "//" to go back to the
original script. Removed one to many... But the original problem I mailed
you about still remains. "Screen stays empty"
Sorry for wasting your time...
Kind regards
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 23 January 2007 09:54 |
Anonymous,
> Screen stays empty
Ok, your server is overriding you, and ignoring your request to set the
Content-Type header. It is being sent as text/html, which causes Firefox and
Safari (and most other browsers) not to parse the response.
This is a copy of the headers your server is sending:
HTTP/1.0 200 OK
Date: Tue, 23 Jan 2007 09:37:19 GMT
Content-Length: 7266
Content-Type: text/html
Cache-Control: private
Server: Microsoft-IIS/5.1
Set-Cookie: ASPSESSIONIDSATRAQAA=NKJPLKFBDFILNNBAGCMMABLB; path=/
I do not know ASP, but I found something that probably explains the problem.
It seems ASP does not let you set that header yourself, and you have to set
it as a property of the response object itself.
response.ContentType = "text/xml"
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 07:23 |
Hi,
That worked! Thanks a lot!
This the translated ASP file:
<%
feedURL = request("feedURL")
fix091 = request("fix091")
temp = "<?xml version="& chr(34) &"1.0"& chr(34) &" encoding="& chr(34) &
"iso-8859-1"& chr(34) &"?>"
if feedURL <> "" then
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "Get",feedURL, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText
RSSXML = replace(RSSXML,temp,"")
RSSXML = temp & vbCrLf & "<?xml-stylesheet type="& chr(34) &"text/css"&
chr(34) &" href="& chr(34) &"empty.css"& chr(34) &
"?>" & vbCrLf & RSSXML
RSSXML = Replace(RSSXML,"<link>","<fixlink>")
RSSXML = Replace(RSSXML,"</link>","</fixlink>")
RSSXML = Replace(RSSXML,"<image>","<fiximage>")
RSSXML = Replace(RSSXML,"</image>","</fiximage>")
RSSXML = Replace(RSSXML,"<rss ","<rssSpoof ")
RSSXML = Replace(RSSXML,"</rss>","</rssSpoof>")
RSSXML = Replace(RSSXML,"<feed>","<atomSpoof>")
RSSXML = Replace(RSSXML,"</feed>","</atomSpoof>")
if fix091 <> "" then
RSSXML = Replace(RSSXML,"version=& chr(34) &0.91& chr(34) & ",
"version=& chr(34) &allowHTML91& chr(34) &")
end if
Response.ContentType = "text/xml"
Response.AddHeader "Content-Length",len(RSSXML)
Response.write RSSXML
else
%>
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="empty.css" ?>
<rssSpoof version="2.0">
<channel>
<title>>Please enter a valid feed URL</title>
<fixlink>http://www.google.com/search?q=rss</fixlink>
<description></description>
<item>
<title>Invalid feed URL detected</title>
<fixlink>http://www.google.com/search?q=rss</fixlink>
<description>RSS newsfeeds are served with a URL beginning with http:// or https://</description>
</item>
</channel>
</rssSpoof>
<%
end if
%>
Please, do with it what you want! And DON'T add any reference to me for translating the file!
[Ed. These emails are anonymous because of this request.]
Thanks for you help!
kind regards
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 08:39 |
Anonymous,
This is great! Thankyou for sharing.
> if feedURL <> "" then
One minor point that needs to be addressed before you use this script; it
must firstly check if the feedURL starts with 'http://' or 'https://' or
they could make it send them random files from your server (so your server's
security is at risk). Or does MSXML2.XMLHTTP already insist on only using
the HTTP or HTTPS protocols?
Cheers
Tarquin
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 09:57 |
Hi,
MSXML2.XMLHTTP:
I did found a couple of examples where they add the "http://" separately and
Just to be sure I tested it:
http://[URL]/rsslocal.asp?feedURL=www.example.com/a.xml -> error!
http://[URL]/rsslocal.asp?feedURL=localrss.asp -> error! [due to a typo]
http://[URL]/rsslocal.asp?feedURL=http://[URL]/a.xml No error!
Conclusion: The MSXML2.XMLHTTP needs "http://" or "https://"
[URL] (your original script using rssLocal.asp) If you forget "http://"
nothing happens.
Reminder: If you want to use the rss.html with the rssLocal.asp you have to
change rssLocal.php to rssLocal.asp
Just to remind you to add it to the readme.txt If you are planning to add it
to your "zip-package".
Kind regards
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 10:10 |
Anonymous,
> Conclusion: The MSXML2.XMLHTTP needs "http://" or "https://"
Nope. I can read potentially sensitive files on your server:
http://[URL]/rsslocal.asp?feedURL=c:\windows\win.ini
> Reminder: If you want to use the rss.html with the rssLocal.asp you
> have to change rssLocal.php to rssLocal.asp
> Just to remind you to add it to the readme.txt If you are planning to
> add it to your "zip-package".
yep, will do, thanks :)
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 11:07 |
Hi,
This would fix the security leak... Hahaha, I'm laughing because I was sure
that The MSXML2.XMLHTTP needed "http://" or
"https://" to function but you immediately showed me different! That's
funny! I'm gonna check for this security bridge in
other scripts! Never crossed my mind that it's that easy. Any ideas what
"they" can do with such info such as "win.ini"?
Kind regards,
Final script!? :
<%
feedURL = request("feedURL")
fix091 = request("fix091")
secure = Split(feedURL,":")
if feedURL <> "" then
if Left(secure(0),4) <> "http" then
feedURL=""
response.write "Your URL as to start with http:// or https://"
else
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "Get",feedURL, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText
temp = "<?xml version="& chr(34) &"1.0"& chr(34) &" encoding="& chr(34) &
"iso-8859-1"& chr(34) &"?>"
titletochange = "nieuwnieuws.nl - Fair and Balanced"
titlechange = "News from: NieuwNieuws.nl"
RSSXML = replace(RSSXML,titletochange,titlechange)
RSSXML = replace(RSSXML,temp,"")
RSSXML = temp & vbCrLf & "<?xml-stylesheet type="& chr(34) &"text/css"&
chr(34) &" href="& chr(34) &"empty.css"& chr(34) &
"?>" & vbCrLf & RSSXML
RSSXML = Replace(RSSXML,"<link>","<fixlink>")
RSSXML = Replace(RSSXML,"</link>","</fixlink>")
RSSXML = Replace(RSSXML,"<image>","<fiximage>")
RSSXML = Replace(RSSXML,"</image>","</fiximage>")
RSSXML = Replace(RSSXML,"<rss ","<rssSpoof ")
RSSXML = Replace(RSSXML,"</rss>","</rssSpoof>")
RSSXML = Replace(RSSXML,"<feed>","<atomSpoof>")
RSSXML = Replace(RSSXML,"</feed>","</atomSpoof>")
if fix091 <> "" then
RSSXML = Replace(RSSXML,"version=& chr(34) &0.91& chr(34) & ",
"version=& chr(34) &allowHTML91& chr(34) &")
end if
Response.ContentType = "text/xml"
Response.AddHeader "Content-Length",len(RSSXML)
Response.write RSSXML
end if
else
%>
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="empty.css" ?>
<rssSpoof version="2.0">
<channel>
<title>>Please enter a valid feed URL</title>
<fixlink>http://www.google.com/search?q=rss</fixlink>
<description></description>
<item>
<title>Invalid feed URL detected</title>
<fixlink>http://www.google.com/search?q=rss</fixlink>
<description>RSS newsfeeds are served with a URL beginning with http://
or https://</description>
</item>
</channel>
</rssSpoof>
<%
end if
%>
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 11:22 |
Anonymous,
> Any ideas what "they" can do with such info such as "win.ini"?
I would be more worried about ntuser.dat and related files - your registry.
Contains most of your stored passwords, etc.
> if Left(secure(0),4) <> "http" then
hrm. would this also work?:
if feedURL <> "" and ( Left(feedURL,7) = "http://" or ( Left(feedURL,8) =
"https://" ) then
If so that would make it cleaner since it could send the pre-prepared XML
error from below.
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 24 January 2007 13:00 |
Hi,
Yep, again you're right!
This would also do the job:
if feedURL <> "" and Left(feedURL,4) = "http" then
but yours maybe better...
Thanks again!
PS I would be more worried about ntuser.dat... So do i have change my passwords? ;-)
Kind regards,
Final final script?!:
<%
feedURL = request("feedURL")
fix091 = request("fix091")
temp = "<?xml version="& chr(34) &"1.0"& chr(34) &" encoding="& chr(34)
&"iso-8859-1"& chr(34) &"?>"
if feedURL <> "" and Left(feedURL,7) = "http://" or Left(feedURL,8) =
"https://" then
'if feedURL <> "" and Left(feedURL,4) = "http" then
Set xmlHttp = Server.CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "Get",feedURL, false
xmlHttp.Send()
RSSXML = xmlHttp.ResponseText
RSSXML = replace(RSSXML,temp,"")
RSSXML = temp & vbCrLf & "<?xml-stylesheet type="& chr(34) &"text/css"&
chr(34) &" href="& chr(34) &"empty.css"& chr(34) &
"?>" & vbCrLf & RSSXML
RSSXML = Replace(RSSXML,"<link>","<fixlink>")
RSSXML = Replace(RSSXML,"</link>","</fixlink>")
RSSXML = Replace(RSSXML,"<image>","<fiximage>")
RSSXML = Replace(RSSXML,"</image>","</fiximage>")
RSSXML = Replace(RSSXML,"<rss ","<rssSpoof ")
RSSXML = Replace(RSSXML,"</rss>","</rssSpoof>")
RSSXML = Replace(RSSXML,"<feed>","<atomSpoof>")
RSSXML = Replace(RSSXML,"</feed>","</atomSpoof>")
if fix091 <> "" then
RSSXML = Replace(RSSXML,"version=& chr(34) &0.91& chr(34) & ",
"version=& chr(34) &allowHTML91& chr(34) &")
end if
Response.ContentType = "text/xml"
Response.AddHeader "Content-Length",len(RSSXML)
Response.write RSSXML
else
%>
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="empty.css" ?>
<rssSpoof version="2.0">
<channel>
<title>>Please enter a valid feed URL</title>
<fixlink>http://www.google.com/search?q=rss</fixlink>
<description></description>
<item>
<title>Invalid feed URL detected</title>
<fixlink>http://www.google.com/search?q=rss</fixlink>
<description>RSS newsfeeds are served with a URL beginning with http://
or https://</description>
</item>
</channel>
</rssSpoof>
<%
end if
%>
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 5 February 2007 10:44 |
Anonymous,
> PS I would be more worried about ntuser.dat... So do i have change my
> passwords? ;-)
:P
> Final final script?!:
I have made a few minor modifications such as:
* removing existing XML stylesheets
* using "foo""bar" instead of "foo"&chr(34)&"bar"
* adding in the right headers for the error feed
I set up a quick test server, and it all seems to be working great.
I have added it to the download. Your script is kept as an anonymous
contribution, at your request.
Thankyou again.
Tarquin
From | Anonymous |
To | Me |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 12 January 2007 21:47 |
Hi Tarquin
Thank you for informing me personally about the update!
I've found one little problem and I think, I know what the problem might be.
Some character found in XML such a é,ê,ë give problems especially at the end
of a "</ title>"
I think the MSXML2.XMLHTTP doesn't "understand" the special characters. It
creates plain text.
Instead of the special character it writes a "?" that's not directly a
problem for me... but in some cases it also removes
"</" before "</ title>" ending up with "?title>" Which results in a XML
error. I've tried a simple
replace(var,"?title","</title") but that's doesn't work either...
At the moment I a run VBS script every hour. It downloads an index.xml of
http://www.nieuwnieuws.nl/ I've changed my code a
little bit instead of using MSXML2...
Dim objFSO, objTextFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(server.MapPath(feedURL))
'--> Set objTextFile =
objFSO.OpenTextFile("D:\InetPub\wwwroot\marcenvera.nl\RSSReader\index.xml")
Do While Not objTextFile.AtEndOfStream
RSSXML= RSSXML & objTextFile.ReadLine
Loop
objTextFile.Close
Set objTextFile = Nothing
Set objFSO = Nothing
I did some research how to get a remote file such as a txt file or a xml
file with ASP.
But without any results except for MSXML2. I'll keep you informed if find a
solution for this problem.
Kind regards
From | Me |
To | Anonymous |
Subject | Re: Problems with RSS/Atom feed parser |
Date | 12 February 2007 22:41 |
Anonymous,
> Some character found in XML such a é,ê,ë give problems especially at
> the end of a "</ title>"
This depends on how they are written. If they are written with entities, it
should work (although that part is handled by the browser's XML parser so IE
may have a bug here). If they are written using the actual characters, you
should make sure the server sends the XML file with the right encoding,
perhaps utf-8 - if I remember rightly, this was another property of the
response object.
response.charSet = "utf-8"
or something like that. Cannot remember exactly off the top of my head.