• 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: How to work with XML data using System Events?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to work with XML data using System Events?


  • Subject: Re: How to work with XML data using System Events?
  • From: Matt Neuburg <email@hidden>
  • Date: Fri, 04 Nov 2005 05:47:56 -0800
  • Thread-topic: How to work with XML data using System Events?

On Tue, 1 Nov 2005 17:17:52 +0000, pete boardman <email@hidden>
said:
>The System Events dictionary contains these commands:
>
>XML attribute
>XML data
>XML element
>XML file
>
>How would I use these to read XML data from an XML file?

Example (from you-know-where):

tell application "System Profiler"
    set s to (XML text of document 1)
end tell
on findElementWithValue(e, v)
    tell application "System Events"
        repeat with i from 1 to (count XML elements of e)
            if value of XML element i of e is v then
                return i
            end if
        end repeat
    end tell
    error "not found"
end findElementWithValue
tell application "System Events"
    set x to make new XML data with data s
    set e to XML element 1 of XML element 1 of x
    set e to first XML element of e where ¬
        value of XML element 2 of it is "SPHardwareDataType"
    set i to my findElementWithValue(e, "_items")
    set e to XML element 1 of XML element (i + 1) of e
    set i to my findElementWithValue(e, "machine_name")
    return value of XML element (i + 1) of e -- iMacG5
end tell

m.

--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to work with XML data using System Events?
      • From: pete boardman <email@hidden>
  • Prev by Date: Re: How to work with XML data using System Events?
  • Next by Date: RE: making applescript wait until shell script finishes
  • Previous by thread: Re: How to work with XML data using System Events?
  • Next by thread: Re: How to work with XML data using System Events?
  • Index(es):
    • Date
    • Thread