LNS Home
XML Tools 2.9
XML Tools Home
Documentation
 
XML Parsing
XML Event-Based Parsing
XML Generation
Encodings
Utility AppleScript Code
Sample Applications
 
WatchNews
XML-RPC
Products
Affrus 1.0
x FaceSpan 4.3
Script Debugger 4.0
Freeware
XML Tools
XSLT Tools
List & Record Tools
Property List Tools
JavaScript OSA
Sample XML-RPC Server
OSAXen Fixer
CodeWarrior Tools
Site Contents
Home Page
bullet Mark’s Blog
Product Registration
Bug Reporting
x Freeware
Contacting Us

The Application

UserLand Software operates the Scripting News web site which offers news items relating to scripting, and in particular to UserLand's Frontier product. A recent addition to the Scripting News site is an XML representation of the news items on the site.

This sample application reads that XML data and displays it in a dialog box where you can double-click on items to view them in your Web Browser.

I used FaceSpan 3.0 in combination with the XML Tools AppleScript Scripting Addition to create a Macintosh application for viewing the XML news items.

The script that does all the work is attached to the Update button. In case you don't have access to FaceSpan, the code is shown below.

on hilited theObj
    local theURL, theFolder, theXML, theNews, theLines

    try
        set enabled of push button "update" to false
        set theURL to contents of textbox "URL"

        --    Go and get the XML data from the provider's site
        tell application "Finder"
            set theFolder to temporary items folder as string
            if exists file "news.xml" of temporary items folder then ¬
                delete file "news.xml" of temporary items folder
        end tell
        tell application "URL Access Scripting"
            activate
            download theURL to file (theFolder & "news.xml") with progress
            quit
        end tell

        --    Extract the news items from the returned XML and prepare them for
        --    display in a FaceSpan table
        set theXML to parse XML (read file (theFolder & "news.xml"))

        set theNews to {}
        repeat with anItem in XML contents of theXML
            if XML tag of anItem is "item" then ¬
                set end of theNews to getItemData(anItem)
        end repeat

        --    Update the table to show the new news items
        delete rows of table "news" of first window
        set contents of table "news" of first window to theNews

        --    Go through and adjust the height of each table item to show all of
        --    the news item. The calculation is a hack, but you get the idea.
        repeat with i from 1 to count items of theNews
            set theLines to (length of item 1 of item i of theNews) div 45
            if theLines < 1 then ¬
                    set theLines to 1
            set height of row i of table "news" of first window to theLines * 14
        end repeat

        set enabled of push button "update" to true
    on error errMsg number errNum
        set enabled of push button "update" to true
        error errMsg number errNum
    end try
end hilited

on
getItemData(theItem)
    local theText, theURL

    set theText to ""
    set theURL to ""

    repeat with aSubItem in XML contents of theItem
        if XML tag of aSubItem is "text" then
            set theText to XML contents of aSubItem as string
        else if XML tag of aSubItem is "link" then
            repeat with aSubSubItem in XML contents of aSubItem
                if XML tag of aSubSubItem is "url" then
                    set theURL to XML contents of aSubSubItem as string
                end if
            end repeat
        end if
    end repeat

    return {theText, theURL}
end getItemData

Requirements

To use and modify this sample application, you'll need to the following:

  • the XML Tools scripting addition
  • FaceSpan 3.0 or later from Digital Technologies International (www.facespan.com)
    You can run the sample application by downloading the FaceSpan Extension from the FaceSpan web site
  • a connection to the internet
  • MacOS 8.6 or later (for the URL Access Scripting component)

Download Sample

Watch News.sit.hqx (49K)

 


Copyright © 1998-2007 Late Night Software Ltd. - All Rights Reserved.