Indigo Rose Software
  #1  
Old 09-25-2005
SonG0han SonG0han is offline
Forum Member
 
Join Date: Dec 2003
Posts: 155
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.
Reply With Quote
  #2  
Old 09-25-2005
SonG0han SonG0han is offline
Forum Member
 
Join Date: Dec 2003
Posts: 155
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.
Reply With Quote
  #3  
Old 09-25-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Quote:
Originally Posted by SonG0han
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.

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
Reply With Quote
  #4  
Old 09-25-2005
SonG0han SonG0han is offline
Forum Member
 
Join Date: Dec 2003
Posts: 155
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.
Reply With Quote
  #5  
Old 09-25-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
Quote:
Originally Posted by SonG0han
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.
What I started to do was create a function for RSS feeds, and one for ATOM feeds. One problem with trying to code for XML is that it can change from place to place, that is the benefit of XML, and when you put namespaces on top of the flexability of XML then you open a whole can of worms. I would suggest you look into the standards you are most interested in and grab a couple of the XML feeds and use them to code your different functions.

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
Reply With Quote
  #6  
Old 09-25-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
Reply With Quote
  #7  
Old 09-25-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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
Reply With Quote
  #8  
Old 09-26-2005
SonG0han SonG0han is offline
Forum Member
 
Join Date: Dec 2003
Posts: 155
Thumbs down

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
----- then i switch page, go back (its an input field with multiline where you add one url per line) and the rss files are saved in newsfeeds.dat (simple textfile). on the frontpage I call the function to read the rss data and generate the .htm file but I delete it prior to that so why can this happen->
Code:
 
channelname1
item1
item2

channelname2
item1
item2
item3

channelname1
item1
item2

channelname2
item1
item2
item3
I have to call the function again to clear it and recreate it. but thats already what I do "on show"

Last edited by SonG0han; 09-26-2005 at 04:57 AM.
Reply With Quote
  #9  
Old 09-26-2005
SonG0han SonG0han is offline
Forum Member
 
Join Date: Dec 2003
Posts: 155
Quote:
Originally Posted by SonG0han
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
----- then i switch page, go back (its an input field with multiline where you add one url per line) and the rss files are saved in newsfeeds.dat (simple textfile). on the frontpage I call the function to read the rss data and generate the .htm file but I delete it prior to that so why can this happen->
Code:
 
channelname1
item1
item2

channelname2
item1
item2
item3

channelname1
item1
item2

channelname2
item1
item2
item3
I have to call the function again to clear it and recreate it. but thats already what I do "on show"
/2nd Edit:
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.
Reply With Quote
  #10  
Old 09-26-2005
TJ_Tigger's Avatar
TJ_Tigger TJ_Tigger is offline
Indigo Rose Customer
 
Join Date: Sep 2002
Location: Sol 3
Posts: 3,188
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.
Reply With Quote
  #11  
Old 09-26-2005
SonG0han SonG0han is offline
Forum Member
 
Join Date: Dec 2003
Posts: 155
Thanks!
I will take a look at your apps.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright © 2000 - 2009 Indigo Rose Corporation. All rights reserved.
Indigo Rose Software