AppleScript, simple GET request

Im trying to rewrite something ive written in Visual Basic that uses an XMLHTTP ‘GET’ request. How do I do this in AppleScript? I can only seem to find information about ‘POST’ requests, which require input/output parameters but I want just the XML that going to this url should output.

This might do what you’re after…

http://www.occupantunknown.com/missinglink/missinglink.html

PB


Doesn’t curl does that for you? Get method is default with curl.

Ok ive got this working, and reading the resulting xml into a variable. However, I want to extract values out of the xml, how to i go about doing this? I want to find the first 5 instances of a tag ()

A simple example will maybe help, this example does get an XML feed (RSS) from macscripter.net and parse it with system events

getRSSFeed("http://www.macscripter.net/extern.php?action=active&type=rss")

on getRSSFeed(URLFeed)
	set RSSItems to {}
	set RSSFeed to do shell script "curl -s " & quoted form of URLFeed
	tell application "System Events"
		set XMLData to make new XML data with data RSSFeed
		repeat with RSSItem in (XML elements of XML element "channel" of XML element "rss" of XMLData whose name = "item")
			set end of RSSItems to {RSSTitle:value of XML element "title" of RSSItem, RSSLink:value of XML element "link" of RSSItem}
		end repeat
	end tell
	return RSSItems
end getRSSFeed

Sorry im quite new to this, but basically my xml is set out like so:


<findItemsAdvancedResponse xmlns="http://www.mysite.com">
...<searchResult count="10">
......<item>
.........<primaryCost>
............<cost>100</cost>


(the . is a space)

And I want to get the , and repeat it for each up to a maximum of 5, how would I do this?

I don’t think any explanation is needed, code speeks for itself.

set theXMLString to "<findItemsAdvancedResponse xmlns=\"http://www.mysite.com\">
<searchResult count=\"10\">
<item><primaryCost><cost>100</cost></primaryCost></item>
<item><primaryCost><cost>70</cost></primaryCost></item>
<item><primaryCost><cost>20</cost></primaryCost></item>
<item><primaryCost><cost>30</cost></primaryCost></item>
<item><primaryCost><cost>100</cost></primaryCost></item>
<item><primaryCost><cost>200</cost></primaryCost></item>
<item><primaryCost><cost>1007</cost></primaryCost></item>
<item><primaryCost><cost>21</cost></primaryCost></item>
<item><primaryCost><cost>43</cost></primaryCost></item>
<item><primaryCost><cost>432</cost></primaryCost></item>
</searchResult>
</findItemsAdvancedResponse>"

set costItems to {}
set x to 1
tell application "System Events"
	set XMLRoot to make new XML data with data theXMLString
	repeat with searchItems in (XML elements of XML element "searchResult" of XML element "findItemsAdvancedResponse" of XMLRoot)
		set end of costItems to value of XML element "cost" of XML element "primaryCost" of searchItems
		if x is not 5 then
			set x to x + 1
		else
			exit repeat
		end if
	end repeat
end tell
return costItems

Ok so thats sorted and I get a list of costItems reported at the bottom of the AppleScript editor. Id like to get this script to run every few minutes, and write the values to the end of a file, how would I do that? Sorry to be a bit of a pain, ive only just started using applescript.