• 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
Fwd: Working with XML
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Working with XML


  • Subject: Fwd: Working with XML
  • From: Anton Linecker <email@hidden>
  • Date: Mon, 26 May 2008 17:11:14 -0700



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      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Working with XML
      • From: Rainer Standke <email@hidden>
    • Re: Working with XML
      • From: Ed Stockly <email@hidden>
  • Prev by Date: Re: Applescript and Cocoa and XCode
  • Next by Date: Re: Working with XML
  • Previous by thread: Re: Applescript and Cocoa and XCode
  • Next by thread: Re: Working with XML
  • Index(es):
    • Date
    • Thread