|
#1
|
|||
|
|||
|
XML Problem - reading Newsfeeds
hi! i wrote some lines to get title and link of each element in a rss newsfeed.
first i used "rdf:RDF" as root path for xml operations but some have others like "<rss version="2.0">". I tried to use "*" as root path and it works for the new file. I tried to use "rss" instead of * with GetElementXML and it showed me the whole file in a dialogbox - so it works, too. The XML Data is in memory wheter I use "*" or "rss". BUT with "*" the rss data of the other files with "rdf:RDF" as root are not shown, i get a blank string. And when I try to access title and link of the ITEMS I get blank strings for the file that has the "<rss version="2.0">" header. Is there an error in the XML Actions or what? I hope you can understand what I mean. Last edited by SonG0han; 09-25-2005 at 02:08 PM. |
|
#2
|
|||
|
|||
|
Here is the current code
I have modified many different things to try to fix it so its a bit messed up now (the part with RSSadd = ... for example). I tried many different ways to get the data but it does not work for the one with <rss version="2.0">. the .dat file contains one url per line. Can anyone of you help me please? Code:
function UpdateNews()
tblRSSFeeds = TextFile.ReadToTable(_SourceFolder.."\\newsfeeds.dat");
if tblRSSFeeds ~= nil then
StatusDlg.SetTitle("Generating News");
StatusDlg.ShowCancelButton(false, "Cancel");
StatusDlg.Show(MB_ICONNONE, false);
File.Delete(_SourceFolder.."\\newsfeed.htm", false, false, false, nil);
txtstring = "<html><head><style type=\"text/css\"><!-- body,td,th {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;color: #000000;} body {background-color: #FFFFFF;} --></style></head><body>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
for index, value in tblRSSFeeds do
if value ~= "" then
File.Delete(_SourceFolder.."\\newsfeed.tmp", false, false, false, nil);
-- Datei herunterladen
HTTP.Download(value, _SourceFolder.."\\newsfeed.tmp", MODE_TEXT, 20, 80, nil, nil, nil);
LastError = Application.GetLastError();
if LastError == 0 then
-- Datei parsen und HTML erstellen
XML.Delimiter = "|";
XML.Load(_SourceFolder.."\\newsfeed.tmp");
RSSPfad = "rdf:RDF";
foundElements = XML.Count(RSSPfad, "item");
--foundElements = XML.Count("rdf:RDF", "item");###
if foundElements == -1 then
RSSadd = "/channel";
foundElements = XML.Count(RSSPfad..RSSadd, "item");
end
if foundElements == -1 then
RSSPfad = "rss";
foundElements = XML.Count(RSSPfad, "item");
end
if foundElements == -1 then
RSSadd = "/channel";
foundElements = XML.Count(RSSPfad..RSSadd, "item");
end
--result = XML.GetElementXML(RSSPfad);
--Dialog.Message("Notice", result, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
--Dialog.Message("Pfad", RSSPfad, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
channel = XML.GetValue(RSSPfad.."/channel/title");
-- channel = XML.GetValue("rdf:RDF/channel/title");###
if channel == "" then
channel = value;
end
channellink = XML.GetValue(RSSPfad.."/channel/link");
if channellink == "" then
channellink = value;
end
txtstring = "<b><font style=\"font-size: 12px\"><a href=\""..channellink.."\" target=\"_blank\">"..channel.."</a></font></b><br>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
if foundElements ~= -1 then
for x = 1, foundElements do
title = XML.GetValue(RSSPfad.."/item|"..x.."/title");
if title == "" then
title = XML.GetValue(RSSPfad.."/channel/item|"..x.."/title");
end
link = XML.GetValue(RSSPfad.."/item|"..x.."/link");
if link == "" then
link = XML.GetValue(RSSPfad.."/channel/item|"..x.."/link");
end
-- link = XML.GetValue("rdf:RDF/item|"..x.."/link");###
txtstring = "- <a href=\""..link.."\" target=\"_blank\">"..title.."</a><br>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
if x == foundElements then
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", "<p>", true);
end
end
else
txtstring = "<p>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
end
end
end
end
txtstring = "</body></html>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
StatusDlg.Hide();
showNews();
end -- rssfeed nicht existent ende
end
with this code the rdf:RDF feeds are shown and the one with "rss version="2.0"" is not visible, just the channelname without any items. (some files contain an additional line on top like: <?xml version="1.0" encoding="ISO-8859-1" ?> ) Last edited by SonG0han; 09-25-2005 at 03:15 PM. |
|
#3
|
||||
|
||||
|
Quote:
You can use "/" to return root elements, then I would check to see if it is rdf or rss and if rss you could then check the version and based on the version retrieve the data you want.
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#4
|
|||
|
|||
|
hmm the "best" would be to support all versions but I dont know every difference between.
most file (rdf:RDF) have this: - channel - item but the rss 2.0 has this - channel - channel > item they are inside the channel. |
|
#5
|
||||
|
||||
|
Quote:
Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#6
|
||||
|
||||
|
It looks like the problem with rdf feeds working and rss feeds not is due to the variable RSSPfad. It is always set to "rdf:RDF" and does not change. I would suggest that when you load your XML file you get the child elements of root "/" and if it is rdf:RDF then do one thing, otherwise if it is rss then do another.
Tigg
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#7
|
||||
|
||||
|
Try this
Code:
function UpdateNews()
tblRSSFeeds = TextFile.ReadToTable(_SourceFolder.."\\newsfeeds.dat");
if tblRSSFeeds ~= nil then
StatusDlg.SetTitle("Generating News");
StatusDlg.ShowCancelButton(false, "Cancel");
StatusDlg.Show(MB_ICONNONE, false);
File.Delete(_SourceFolder.."\\newsfeed.htm", false, false, false, nil);
txtstring = "<html><head><style type=\"text/css\"><!-- body,td,th {font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 10px;color: #000000;} body {background-color: #FFFFFF;} --></style></head><body>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
for index, value in tblRSSFeeds do
if value ~= "" then
File.Delete(_SourceFolder.."\\newsfeed.tmp", false, false, false, nil);
-- Datei herunterladen
HTTP.Download(value, _SourceFolder.."\\newsfeed.tmp", MODE_TEXT, 20, 80, nil, nil, nil);
LastError = Application.GetLastError();
if LastError == 0 then
-- Datei parsen und HTML erstellen
XML.Delimiter = "|";
XML.Load(_SourceFolder.."\\newsfeed.tmp");
tbElements = XML.GetElementNames("/", true, false);
if tbElements[1] == "rdf:RDF" then
RSSPfad = "rdf:RDF";
foundElements = XML.Count(RSSPfad, "item");
channel = XML.GetValue(RSSPfad.."/channel/title");
channellink = XML.GetValue(RSSPfad.."/channel/link");
--foundElements = XML.Count("rdf:RDF", "item");###
--[[if foundElements == -1 then RSSadd = "/channel"; foundElements = XML.Count(RSSPfad..RSSadd, "item"); end
if foundElements == -1 then RSSPfad = "rss"; foundElements = XML.Count(RSSPfad, "item"); end
if foundElements == -1 then RSSadd = "/channel"; foundElements = XML.Count(RSSPfad..RSSadd, "item"); end]]
elseif tbElements[1] == "rss" then
RSSPfad = "rss";
channel = XML.GetValue(RSSPfad.."/channel/title");
channellink = XML.GetValue(RSSPfad.."/channel/link");
foundElements = XML.Count(RSSPfad.."/channel", "item");
end
--result = XML.GetElementXML(RSSPfad);
--Dialog.Message("Notice", result, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
--Dialog.Message("Pfad", RSSPfad, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
txtstring = "<b><font style=\"font-size: 12px\"><a href=\""..channellink.."\" target=\"_blank\">"..channel.."</a></font></b><br>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
if foundElements ~= -1 then
for x = 1, foundElements do
if tbElements[1] == "rdf:RDF" then
title = XML.GetValue(RSSPfad.."/item|"..x.."/title");
link = XML.GetValue(RSSPfad.."/item|"..x.."/link");
elseif tbElements[1] == "rss" then
title = XML.GetValue(RSSPfad.."/channel/item|"..x.."/title");
link = XML.GetValue(RSSPfad.."/channel/item|"..x.."/link");
end
txtstring = "- <a href=\""..link.."\" target=\"_blank\">"..title.."</a><br>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
if x == foundElements then
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", "<p>", true);
end
end
else
txtstring = "<p>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
end
end
end
end
txtstring = "</body></html>";
TextFile.WriteFromString(_SourceFolder.."\\newsfeed.htm", txtstring, true);
StatusDlg.Hide();
showNews();
end -- rssfeed nicht existent ende
end
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine |
|
#8
|
|||
|
|||
|
GREAT! It is working now!
Just had to add a "/" in front of rss and rdf:RDF (if tbElements[1] == /xxx) and I added the "if channel or channellink == "" use value" to show the URL if no channel exists in the file. I tried too hard to find the error and could not find the "RSSPfad" problem after editing it so often. Thank you very much! I hope this will work for most files now because I did not find much info about the RSS standards and different file structures yet. /edit: one thing I noticed is that sometimes the RSS Data is there twice or more times after switching pages or editing the rss sources on the preferences page. it looks like this: Code:
channelname1 item1 item2 channelname2 item1 item2 item3 Code:
channelname1 item1 item2 channelname2 item1 item2 item3 channelname1 item1 item2 channelname2 item1 item2 item3 Last edited by SonG0han; 09-26-2005 at 04:57 AM. |
|
#9
|
|||
|
|||
|
Quote:
Seems it is fixed now, I called the funcion on Preload, I added it to the other on Show actions and now it seems to update properly. but I don't really know why yet. The web.loadurl seemed to work on preload. |
|
#10
|
||||
|
||||
|
Here is the RSS 2.0 spec.
http://blogs.law.harvard.edu/tech/rss If you google for rss and rdf you will find a lot of pages with the content. My suggestion would be to look at the feeds that you are most interested in or those which seem to be most popular and build your project around those feeds. If you follow what they do then you should be able to read most of the files. Tigg Here is the aggregator and XML parser I have been playing with. The aggretator doesn't have everything in it I want to put in it, but it is fun to play with.
__________________
TJ-Tigger "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools." "Draco dormiens nunquam titillandus." Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine Last edited by TJ_Tigger; 07-13-2006 at 08:39 AM. |
|
#11
|
|||
|
|||
|
Thanks!
I will take a look at your apps.
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with XML plugin | TJ_Tigger | AutoPlay Media Studio 5.0 | 13 | 09-07-2004 04:15 PM |
| Problem reading PATH value in Windows Registry | fhernandez | Setup Factory 6.0 | 5 | 03-27-2003 01:57 PM |
| Problem with reading from registry | madmax | Setup Factory 6.0 | 3 | 11-01-2002 09:40 AM |
| INFO: Tips for Debugging Action Lists in AutoPlay Media Studio 4.0 | Support | AutoPlay Media Studio 4.0 Examples | 0 | 10-03-2002 09:38 AM |
All times are GMT -6. The time now is 07:10 PM.








Linear Mode

