An already compiled script module can be appended with new global functions and global variables through the use of asIScriptModule::CompileFunction and CompileGlobalVar, but it is not possible to append arbitrary scripts that may contain multiple functions, classes, etc.
Even if it was possible to append to an existing module (which is actually something I already have on my to-do list), I'm not sure it would be easy to remove part of the module when your GUI loaded a different document. How should the application or script engine know what should be removed?
Perhaps you could do something like this:
1. When loadDocument is called
2. Application serializes any existing objects, values in the module (i.e. store a backup)
3. Create a new module
4. Add the original "inventory.as" script, plus all the embedded script sections from the XML
5. Compile the module
6. If the compilation is successful, restore (deserialize) the objects and values from the previous backup
This is often known as 'hot loading' modified scripts, and normally used to allow the source code to be modified on-the-fly, but should work perfectly in your case too. The serializer add-on can be used to make the backup of values and objects and then restore them.