Hi All
I’ve spent the last week or two working out how to properly parse an XML file using System Events as opposed to the alternate methods of changing text delimiters and substringing, and resorting to using latenight softwares add-in. I have found the System Events parsing quite simple really (please understand I am a real noob with all this stuff).
With that said I haven’t seen an easy to follow example of how to parse XML on the web, instead I’ve had to grab stuff from all over the place. Reading the XML data in from a file only means changing (a) adding the "-o “posix path / filename” to the curl call, and (b) loading the file and converting its contents to XML using the statement “set theReturnedXML to contents of XML file ‘path to the file’”
Hope this helps others …
Cheers
MacP
(* xml data file contents
<?xml version="1.0" encoding="utf-8"?>
<bpudb_app release="31 Mar 2008">
<version>1.0.1</version>
<release-date>31 Mar 2008</release-date>
<download-url>http://www.abc.com/apps/bpudb/bpudb.dmg</download-url>
<supported>True</supported>
<osv>1.00</osv>
</bpudb_app>
*)
property myURL : "http://www.abc27.com/version_files/"
property myVersionFile : "text.xml"
property myCurl : "usr/bin/curl --silent --show-error" & space
set theCurlCall to myCurl & myURL & myVersionFile
set theReturnedXML to (do shell script "" & theCurlCall & "")
tell application "System Events"
try
set mainXML to make new XML data with data theReturnedXML
set rootXML to first XML element of mainXML
set server_date to value of (XML attribute "release" of rootXML)
set server_version to value of (XML element "version" of rootXML)
set server_release_date to value of (XML element "release-date" of rootXML)
set server_download_url to value of (XML element "download-url" of rootXML)
set server_supported to value of (XML element "supported" of rootXML)
set server_osv to value of (XML element "osv" of rootXML)
on error
-- include your own error handling here - either setting default values or quitting
display dialog "Could not gather version information from server, exiting" buttons {"Cancel"}
quit
end try
end tell
display dialog "Server Date: " & server_date as string
display dialog "Server Version: " & server_version as string
display dialog "Server Release Date: " & server_release_date as string
display dialog "Server Download URL: " & server_download_url as string
display dialog "Support Offered: " & server_supported as string
display dialog "Oldest Support Version: " & server_osv as string