Hey guys,
Thanks again for all the great help. I am using XMLlib and have been very successful in extracting values of interest from my XML generated from Final Cut server.
Now I am having some issues in that my goal is to read in an XML file, remove an entry, and write that back out to file for later processing. I can read in the XML, parse it and remove the entry of interest successfully (using XMLDisplayXML to see my results) but I am having issues getting that changed data back to disk.
1. It is unclear to me whether I can use XMLLib to directly affect the file on disk or if I have to (as I am here) read in the file as text to a variable and then process that using XMLOpen...etc and then put that XML data back into text and write that new text file out to disk.
2. I haven't had this issue before, but my "open for access" works just fine to read in the file, but as soon as I add "with write permission" I get a -49 error that the file is already open (thus I added "try to close the file" first and still get the error). Anyone want to comment about this as I think I've been staring at it too long and can't see the error of my ways.
Again, thanks again, you guys have been great and thanks in advance for your comments on this one.
Cheers,
Steve
Here is the portion of code of interest:
-- path to XML file to be modified set the tempXML to "/Volumes/BCP_XSAN/fcsvr/TEMP/tempxmltest.txt"
-- ask Final Cut Server to generate the XML file do shell script "\"" & fcsCommand & "\"" & " getmd --xml /asset/" & assetID & " > " & tempXML
-- I keep getting "file already open (-49) errors, so I tried to make sure it was closed - didn't help try close access tempXML end try
-- open XMLfile and prep as XML set xmlFileText to (open for access tempXML with write permission) -- this is where I get -49 set XMLtext to XMLOpen (read xmlFileText for (get eof xmlFileText) as Unicode text)
-- find the index of the XML entry of interest set the_root to XMLRoot of XMLtext set the_child to XMLChild the_root index 1 XMLNodeInfo the_child set theCount to the XMLCount of the_child
repeat with i from 1 to theCount set the_child2 to XMLChild the_child index i set theValueID to item 2 of attribute of (XMLNodeInfo the_child2) if theValueID is "ASSET_TYPE" then set theENTRY to i end repeat
-- once the index is found, remove that entry set theOne to XMLChild the_child index theENTRY XMLDisplayXML theOne XMLRemove theOne
-- try to write the resulting XML text back to the file set xmlFileText to XMLGetText the_root write xmlFileText to tempXML
-- close file on HDD close access tempXML
|