Re: Applescript & Final Cut Server & XML
Re: Applescript & Final Cut Server & XML
- Subject: Re: Applescript & Final Cut Server & XML
- From: Stan Cleveland <email@hidden>
- Date: Tue, 25 May 2010 15:59:10 -0700
- Thread-topic: Applescript & Final Cut Server & XML
Title: Re: Applescript & Final Cut Server & XML
On 5/25/10 2:29 PM, "Steve Thompson" wrote:
Currently, I'm trying to retrieve certain values from Final Cut Server by issuing the following:
set assetMeta to do shell script fcsvrClientCmd & " getmd --xml" & assetIDString
which gets me the following XML loaded into assetMeta:
<?xml version=\\\"1.0\\\"?>
<session>
<values>
<value id=\\\"PA_MD_CUST_TALENT_PRIMARY\\\">
<string xml:space=\\\"preserve\\\">I.M. Talented</string>
</value>
<value id=\\\"CUST_SIZE\\\">
<bigint>362716863</bigint>
</value>
....
<value id=\"PA_MD_CUST_CONTACT_EMAIL\">
<string xml:space=\"preserve\">email@hidden</string>
</value>
<value id=\"ASSET_VIDEO_ELEMENTS\">
<atom>video</atom>
</value>
</values>
</session>
What's throwing me is how to get to a particular value from AS. I'm familiar with Final Cut Pro XML's and have successfully parsed that data using the System Events dictionary, but Final Cut Pro is simple nested keys, not the value attributes (if that is the correct terminology) here. Not to mention that whenever I try to use a "set x to the value of XML element "xxx" of XML element "yyy" of the contents of XML data assetMeta" I get the following error:
error "System Events got an error: Can’t get contents of XML data \"<?xml version=\\\"1.0\\\"?>...
I've tried loading assetMeta as text and as string and can't seem to figure out how to recognize it as XML data.
Hi Steve,
While I’m not familiar with Final Cut Server, I have a little bit of XML experience. Personally, I use the freeware XMLLib.osax from Late Night Software, rather than System Events for XML, but both are viable options.
Your biggest issue seems to be extra backslashes in the XML. In AS strings, a backslash acts to escape certain troublesome characters, including backslashes and quote marks. In your XML, each triple-slash and quote mark (\\\”) will be interpreted by AS as one slash and a quote mark (\”). This might be perfect for use in a shell command, but won’t work for native AppleScript.
What AS needs in the XML is just one backslash and a quote mark (\“), which it interprets as just a quote mark (“). By manipulating the text to eliminate two of the original three backslashes, your XML will be AS-friendly. Here is some sample code (with XMLLib commands in purple) that parses the snippet of XML you provided (if the ellipsis is deleted first).
-- eliminate extra backslashes
set AppleScript's text item delimiters to "\\\""
set textParts to text items of xmlText
set AppleScript's text item delimiters to "\""
set xmlText to textParts as text
set AppleScript's text item delimiters to ""
-- parse the XML
set theXML to XMLRoot (XMLOpen xmlText)
set sessionXML to XMLChild theXML index 1
set sessionCount to XMLCount of sessionXML
set sessionValues to {}
repeat with i from 1 to sessionCount
set thisValue to XMLChild sessionXML index i
set valueTag to item 2 of attribute of (XMLNodeInfo thisValue)
set valueValue to XMLGetText thisValue
set end of sessionValues to {valueTag, valueValue}
end repeat
XMLClose theXML
return sessionValues
Hope that gets you going in the right direction.
Stan C.
_______________________________________________
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