• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: XML parsing from AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML parsing from AppleScript


  • Subject: Re: XML parsing from AppleScript
  • From: Mark Alldritt <email@hidden>
  • Date: Mon, 22 Jan 2007 08:40:50 -0800
  • Thread-topic: XML parsing from AppleScript

Hi,

> Is anybody aware of an XML parsing module/Scripting Addition in
> AppleScript, so that it reads an XML file, parses it and gives the
> content in an AppleScript data structure?

I offer the XML Tools scripting addition which converts XML data into a
nested structure of AppleScript lists and records:

    http://www.latenightsw.com/freeware/XMLTools2/index.html

However, if you are trying to extract information from an XML file, there is
a better way.  I offer the XSLT Tools scripting addition which allows you to
use XPath expressions to pull information out of an XML file without having
to interpret the file's data structure in AppleScript -- see the 'extract
from XML' command here:

    http://www.latenightsw.com/freeware/XSLTTools/index.html

Here are some simple examples of the 'extract from XML' command that appear
in the XSLT Tools dictionary:

set theXML to "<?xml version=\"1.0\"?>
<data>
   <date>Monday, March 24, 2006</date>
   <performer name=\"Tom Jones\" />
   <performer name=\"Alicia Keys\" />
   <performer name=\"Jessie Winchester\" />
</data>
"

-- extract the <date> element value
extract from xml theXML matching "/data/date" expression "text()"
--> { "Monday, March 24, 2006" }

-- extract only the <performer> elements as XML
extract from xml theXML matching "/data/performer"
--> "<output>
--> <performer name=\"Tom Jones\"/>
--> <performer name=\"Alicia Keys\"/>
--> <performer name=\"Jessie Winchester\"/>
--> </output>
--> "

-- extract the <performer> name attribute values
extract from xml theXML matching "/data/performer" expression "@name"
--> {
-->   "Tom Jones",
-->   "Alicia Keys",
-->   "Jessie Winchester"
--> }

-- extract a single performer's name value
extract from XML theXML matching "/data/performer[2]" expression "@name"
--> { "Alicia Keys" }

Cheers
-Mark

------------------------------------------------------------------------
Mark Alldritt                      Late Night Software Ltd.
Phone: 250-380-1725                Script Debugger 4.0 - AppleScript IDE
WEB:  http://www.latenightsw.com/  FaceSpan 4.3 - AppleScript RAD
                                   Affrus 1.0 - Perl Debugging


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: XML parsing from AppleScript
      • From: "Gary (Lists)" <email@hidden>
  • Prev by Date: Alias Switches allegiance
  • Next by Date: Re: Alias Switches allegiance
  • Previous by thread: Re: XML parsing from AppleScript
  • Next by thread: Re: XML parsing from AppleScript
  • Index(es):
    • Date
    • Thread