extracting text from XML

Hi, I am an applescript newbie.
I want the title and url (e.g. http://media.bloomberg.com/bb/avfile/Economics/On_Economy/vKdJn8CDUcgM.mp3) of each episode of the podcast “Bloomberg on the Economy”.

The XML file starts with

And after this, the text that is repeated for each episode is of this format:

I referred some posts in this forum and began scripting:

set XMLfile to ((path to desktop as text) & "ontheeconomy.xml")
tell application "System Events"
	tell contents of XML file XMLfile
		tell XML element 1
			set Episodelist to value of XML element "title"
		end tell
	end tell
end tell

and i got the error:

I also tried using XML element “channel” instead of “1”.

I referred few other scripts in this forum (http://macscripter.net/viewtopic.php?id=27844, http://macscripter.net/viewtopic.php?id=27100) but I could not find anything different than what I have done.

Please help me.

Hi,

try this


set XMLfile to ((path to desktop as text) & "ontheeconomy.xml")
tell application "System Events"
	tell contents of XML file XMLfile
		tell XML element 1 -- <rss>
			set Episodelist to value of XML element "title" of XML element 1 -- <channel>
		end tell
	end tell
end tell

Thanks, StefanK.
I could extract the link and title for the first episode.

set XMLfile to ((path to desktop as text) & "ontheeconomy.xml")
tell application "System Events"
	tell contents of XML file XMLfile
		tell XML element 1 -- <rss>
			tell XML element 1 -- <channel>
				tell XML element "item"
					set linklist to {"link: " & value of XML element "link"}
set titlelist to {"title: " & value of XML element "title"}
				end tell
			end tell
		end tell
	end tell
end tell

But I am still unable to do it for all the episodes. The element precedes each block of code related to an episode and the element ends such block.
I am sure my answer lies in the script located at http://macscripter.net/viewtopic.php?pid=105042#p105042 but i have failed to use the repeat properly.

you have to find the XML element, which contains all “item” elements, then you can go thru the items

thanks for the reply.
the xml file ends with

which means channel must contain all “item” elements. I have been trying to set up my repeat loop on that assumption for an hour now. It is not working. It fails to go past the first “title” or “link”. Here’s is the xml for your reference: http://www.bloomberg.com/media/podcast/ontheeconomy.xml

try this


set XMLfile to ((path to desktop as text) & "ontheeconomy.xml")
tell application "System Events"
	tell contents of XML file XMLfile
		tell XML element 1 -- <rss>
			set itemElements to XML elements of XML element 1 whose name is "item"
		end tell
	end tell
	set linkList to {}
	set titleList to {}
	repeat with oneItem in itemElements
		set end of titleList to value of XML element "title" of oneItem
		set end of linkList to value of XML element "link" of oneItem
	end repeat
end tell

thank you, StefanK. I did not use “whose name is”.