read online xml-file and display contents in separate text fields

I have stored three variables in an online XML-document: title, text and extended text. Now I want to fetch these variables from the XML-file and display them in three separate text fields. Does anyone know how to do this?

Browser: Safari 412, Xcode 2.1
Operating System: Mac OS X (10.4)

which part? getting the xml or sending to text field?
you can use late night softwares xml scripting addition to convert the xml into an applescript list, then just set them to variables
then you can sen them to text feilds using this code

tell window "WindowName"
set contents of text field "TextFieldName" to VariableName
end tell

you can also do it like this

set contents of text field "TextFieldName" of window "WindowName" to VariableName

but the firs option is better for you as you want to send 3 variables to 3 different text fields in the same window, so you can put them all in one tell block

Thanks a lot! But is it also possible to get the xml without using third party tools? I want to make my program downloadable by others, and I would prefer them not having to install third party tools just to run my program. Or am I missing the point here?

it depends how simple the xml is. what program creates the xml? you can bundle the scripting addition into your script, read about that here: , the second question on the page

Well, all I’m trying to do is acces information that is in an online mysql-database. Since Applescript doesn’t support connecting to a remote mysql database directly, I figured I’d write a php script that outputs simple XML for Applescript. In my script, there’s only three variables:

title text extended

Do I really need third-party tools to fetch these three variables and display them in separate text-fields?

I imagine I will need a curl command to fetch the data form the online XML-file

Then make a loop to get each variable

Then put each variable contents into the right textfield.

Could anyone help me with a code example?

Applescript can communicate with XML-RPC and SOAP, so that would be a good place to look. (though i have no experience with it, but some other member might be able to help you with that)
also, can your script save a text file with 3 lines, a value on each, without the xml tags? if so, it would be super easy to import it into applescript.

Thanks for pointing me to these alternatives, Lobsterman!

I can certainly rewrite my php script to display the variables on three seperate lines, without the tags. How can I then import those variables into applescript? It sounds like a great option to me!

set openDoc to open for access file "path to file"
set readDoc to read openDoc
close access openDoc
set ditd to text item delimiters
set text item delimiters to "\r"
set var1 to text item 1 of readDoc
set var2 to text item 2 of readDoc
set var3 to text item 3 of readDoc
set text item delimiters to ditd

you can also put the variables in the text document on the same line, and put a separating character in between them (like “|” or “*”) and set that character to the text item delimiter instead of “\r” (return) I’m pretty sure its possible without the text item thing, but i cant remember how right now, but this also works.

Thanks a lot!

But can I do this:

set openDoc to open for access file ""

The file I’m trying to read is on a remote webserver, so using a path isn’t an option…

Um, as discussed ad nauseam, this can be simply:

set {var1, var2, var3} to (read ("path:to:file" as alias))'s paragraphs 1 thru 3

By the same token, you can use this for web files:

set {var1, var2, var3} to (do shell script "curl [url=]")'s[/url] paragraphs 1 thru 3


Thanks for helping me out! It works great!