Can I programatically import a class from an XML file?
If I export a class definition to an XML file, is there a way to programmatically import it so that I could schedule a task to look in a given location for XML files once a day and import class definitions?
Comments
%System.OBJ.Load() imports and compiles classes and can be run from another routine or class.
Thanks, that's exactly what I'm looking for!
Yes, you can!
Access your XML file as a binary stream, then you can use the LoadStream command to load & compile the stream.
S STREAM=##class(%Stream.FileBinary).%New()
S STFILE=STREAM.LinkToFile("c:\where\is\your\file.xml")
D STREAM.Rewind()
; test loading the stream, doesn't actually create it yet. The last '1' parameter means test & report.
D $System.OBJ.LoadStream(STREAM,"ckfsbry/lock=0",.ERR,.LOADED,1)
; You can check the ERR variable to see if it errors out with no changes to the system. Assuming none, rewind & load it "for real"
D STREAM.Rewind()
D $System.OBJ.LoadStream(STREAM,"ckfsbry/lock=0",.ERR,.LOADED)I haven't tested this in this manner, as I actually have the XML Base-64 encoded in a global... but hopefully this should get you started. PM me if you'd like to see my full code; it's too long to add here.
I'll leave the scheduling part as an exercise to the reader. :-)
Hope this helps!