Re: Working with XML
Re: Working with XML
- Subject: Re: Working with XML
- From: Rainer Standke <email@hidden>
- Date: Mon, 26 May 2008 20:51:16 -0700
I'd recommend using XMLLib from Satimage, because it includes XPath.
Xpath allows for very finely honed targetting and querrying. It's
an .osax.
Rainer
On May 26, 2008, at 17:11 , Anton Linecker wrote:
Hello all,
I am working on parsing some XML with Applescript:
What I have so far is this:
global target_file
global theXML
global thetitle
tell application "System Events"
activate
set thefile to (choose file without invisibles)
set x to the POSIX path of thefile
set f to the XML file x
set root to XML element 1 of f
set NextRoot to XML element 1 of XML element 1 of f
get properties of root
get properties of NextRoot
get value of every XML element of NextRoot
set theHost to the value of XML element 2 of NextRoot
set theSynopsis to the value of XML element 6 of NextRoot
set theMusic to the value of XML element 3 of NextRoot
set thetitle to the value of XML element 1 of NextRoot
end tell
set theXML to ("<?xml version=\"1.0\"?>
<FinalCutServer>
<entity entityType=\"asset\" entityId=\"/asset/" & thetitle & "\">
<metadata>
<mdValue fieldName=\"Host\" dataType=\"string\">" & theHost &
"</mdValue>
<mdValue fieldName=\"Musical Guest\" dataType=\"string\">" &
theMusic & "</mdValue>
<mdValue fieldName=\"Synopsis\" dataType=\"string\">" &
theSynopsis & "</mdValue>
</metadata>
</entity>
</FinalCutServer>")
set target_file to ((path to desktop) & thetitle & ".xml")
try
set theTarget to (target_file as alias)
if theTarget exists then
tell application "Finder"
delete theTarget
end tell
end if
end try
write_to_file(theXML)
end run
on write_to_file(theXML)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
set eof of open_target_file to 0
write theXML to the open_target_file starting at eof
close access the open_target_file
on error
try
close access file target_file
end try
end try
end write_to_file
This script works well providing the XML that is getting ingested
is simple (one clip).
But it doesn't when you have two or more records in the XML. How can
I get it to read past the first record?
Thanks,
A.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
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/archives/applescript-users
This email sent to email@hidden