Welcome back!

infile  ; simple file read
  set filename="C\mydir\myfile.txt"
  set $ZTRAP="end"
  open filename:("R"):0 else  Write "file error"
  for line=1:1 use filename read text use 0 write text,! 
end
 close filename
  set $ZTRAP=""
  use 0 write "Done",
  quit

it's not so sophisticated and I used the end-of-file error to exit

This is also available in class %Library.File with lot more comfort 
http://docs.intersystems.com/latest/csp/documatic/%25CSP.Documatic.cls?P...

HTH
 

If you don't want / need the content as object and just want to convert XML2JSON
why wasting time and energy to re-invent the wheel an not just using any of the many downloadable tools
and call them over $ZF(-2)  and consume the result ?
Google gave my some thousand hits of tested solutions e.g. https://github.com/sinelaw/xml-to-json

I mean it's doable with Caché but file_in => file_out is not more than a nice exercise for training.
 

%On... callbacks are served and integrated into he OBJECT world and typically don't care about any Trigger.

Triggers live in the SQL TABLE world of your class, with a hand full off %-variables unknown at the Object side
and without an actual instance of object but directly writing to Globals.

Take a look to the generated .INT code of your class and see what you have at hands.
I always found it quite ambitious to attempt a common code of both sides when directly changing Objects or Tables.

Summary:
- for SQL access have Triggers
- for Object access have your %On* methods

Applies only before 2014.1 as pointed out. 
But Trigger code doesn't look much better. 

something similar:

start ;
 open infile:"R":0 else  write "input file not found",! quit
 open outfile:"WNS":0 else  write "error creating output file",! quit 
 set $Zt="end"
 for line=1:1:5 {
  use infile read sql use 0
  if $e(sql,1,6)'="SELECT" continue
  set rs=##class(%ResultSet).%New()
  set sc=rs.Prepare(sql)
  set:sc sc=rs.Execute()
  if 'sc write "bad SQL statement",! quit
  set cols=rs.GetColumnCount()
  use outfile
;; fill in headers if required
  while rs.Next() {
   for cols=1:1:cols write rs.GetData(cols),$c(9)
   write !
  }
  write !,"###",!
  use 0
 }
 
end set $ZT=""
 close infile,outfile quit
 
!! NOT TESTED !!