problem writing out XML suite parsed file to disk

I am having problems writing out the contents of an XML file that has
been parsed in using XML suite to a new file. Using a test app, shown
below, I consistently get the error message:

An error was encountered writing the file to: “my file path”. Error:
System Events got an error: File some object wasn’t open.

The bold text is the relevent error!

The test app code is shown below:


set thePodcast to ""
set xmlFile to "/Path/To/XMLFILE/file1.xml" --an illustration path
tell application "System Events"
	set thePodcast to (contents of XML file xmlFile)
end tell

set posixPath to "/Path/To/XMLFILE/file2.xml"
set file_path to POSIX file posixPath

try
	set open_file to open for access file_path with write permission
	set eof of the open_file to 0
	write thePodcast to open_file starting at eof
	close access file file_path
on error error_message
	try
		close access file file_path
	end try
	display dialog "An error was encountered writing the file to: " &  
file_path & ". Error: " & error_message
end try

I have also tried


	tell application "System Events"
		write text of thePodcast to open_file starting at eof
	end tell
	close access file file_path

and it brings up the same error. I don’t get the error if I just
write a text string or suchlike to the open_file, so I suspect I am not doing
something with XML suite that I should be doing! Anyone have any
suggestions?

You ended with “I have also tried”. Were you going to say you tried writing something to the file completely unrelated to the xml? Is thePodcast really what you think it is?

Argggh, sorry about that - full post should have been…

I am having problems writing out the contents of an XML file that has been parsed in using XML suite to a new file. Using a test app, shown below, I consistently get the error message:

An error was encountered writing the file to: “my file path”. Error: System Events got an error: File some object wasn’t open.

The test app code is shown below:


set thePodcast to ""
set xmlFile to "/Path/To/XMLFILE/file1.xml"
tell application "System Events"
	set thePodcast to (contents of XML file xmlFile)
end tell

set posixPath to "/Path/To/XMLFILE/file2.xml"
set file_path to POSIX file posixPath

try
	set open_file to open for access file_path with write permission
	set eof of the open_file to 0
	write thePodcast to open_file starting at eof
	close access file file_path
on error error_message
	try
		close access file file_path
	end try
	display dialog "An error was encountered writing the file to: " & file_path & ". Error: " & error_message
end try

I have also tried write out the contents using the following:


	tell application "System Events"
		write text of thePodcast to open_file starting at eof
	end tell
	close access file file_path

and it brings up the same error. I don’t get the error if I just write a plain string or suchlike to the open_file, so I suspect I am not doing something with XML suite that I should be doing, rather than it being a permissions issue with the targeted file! Anyone have any suggestions?

I now have a version that works! The problem was that I originally had a line that retrieved the text from thePodcast xml reference, and wrote it out. This line was within a tell block that addressed System Events (for the XML suite processing).

Seperating out the lines and bringing the write statement outside the tell block resolved the problem I was having… The working code section is shown below:


try
	set the open_file to open for access file_pointer with write permission
	set eof of the open_file to 0
	tell application "System Events"
		set podcastText to text of thePodcast
	end tell
	write podcastText to open_file starting at eof
	close access open_file
on error error_message number error_number
	close access open_file
	display dialog "An error was encountered writing the file to: " & open_file & ". Error: " & error_message
end try