Howdy all,
I’m venturing into the heady realm of XML and Applescript. Seeing as I only need to set the contents of an XML file to a text field, I don’t see any reason to use the scripting addition (Besides, I don’t want to have to mess with the end-user having to get that same scripting addition, which they would have to do for it to work. Correct me if I’m wrong :P)
Anywho, we have an xml file containing our data…
<?xml version="1.0" encoding="utf-8"?> Test Song Test Artist Test Album Test Guitar www.test.com One to Five ---1----2---3---4---5--- ----1----2---3---4---5--- ----1----2---3---4---5--- ----1----2---3---4---5--- ----1----2---3---4---5--- ----1----2---3---4---5---And then we have our script to get the info and set it to a text field.
--I took out the properties here for simplicity's sake, but they're there
-- Script
on clicked theObject
if name of theObject is "ImportTab" then
choose file with prompt "Please Choose your xtab file" without invisibles
set tabfile to the result as Unicode text
loadtab()
end if
end clicked
-- Handlers/Functions
on loadtab()
log "loadtab"
tell application "System Events"
log "telling"
tell contents of XML file tabfile
log "1"
set songtitle to contents of XML element "songtitle" of XML element "Tab"
log "2"
(*set songartist to value of XML attribute "songartist" of XML element "Tab" of tabcontents
set songalbum to value of XML attribute "songalbum" of XML element "Tab" of tabcontents
set writtenfor to value of XML attribute "writtenfor" of XML element "Tab" of tabcontents
set originsite to value of XML attribute "originsite" of XML element "Tab" of tabcontents
set difficulty to value of XML attribute "difficulty" of XML element "Tab" of tabcontents
set tabs to value of XML attribute "Tabs" of XML element "Tab" of tabcontents*)
end tell
end tell
set contents of text field "songfield" to songtitle
end loadtab
I get an error saying that “Can’t make contents of XML element “songtitle” of XML element “Tab” of contents of XML file (path:to:file:here) into type reference”. The logs I threw in there only log up to “Loadtab”. (We’re only concerned about the first one for now, I can repeat the steps on the later ones)
As far as I know, that should work, but it clearly isn’t. I have limited knowlage of XML, so I may have missed something. Or is System Events just not capable of doing what I’m trying to do? (I also apologize if this isn’t the right section, but it seemed to be the most appropriate)
Any pointers are appreciated
Thanks!
-Parrot