Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing xml



Hi Chuck,

Users on this list tipped me off to some way cool ways of accessing XML
files.

Use this as a general reference only---  I am typing this away from my
scripting machine and don't have a way to test as I write.

Say the xml file is "test.xml" on your desktop.  It contains an xml tree
where "Book" is the first level, and "Chapter" is the 2nd.

-- =====

--Getting the values (parsing):

set xmlFile to POSIX path of ((path to desktop as string) & "test.xml")
set myRecordList to (call method "dictionaryWithContentsOfFile:" of class
"NSDictionary" with parameter xmlFile ) as record
set theFirstLevel to |Book| of myRecordList
set theSecondLevel to call method "allValues" of theFirstLevel

--Setting values:

Set |name| of item 1 of theFirstLevel to "Da Vinci Code"

--Writing the file back:

set didWrite to call method "writeToFile:atomically:" of myRecordList with
parameters { xmlFile , "YES"}

-- =====

You'll have to do some testing, and search the documentation and lists for
more examples, but if you use these methods it makes things SUPER easy!

Hope this helps,
Graham Jones.


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

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.