The key to your problem is, how one can inline the DTD content inside XML text.
This is done as follows:
<!DOCTYPE foo SYSTEM "someExternal.dtd" [
><!ENTITY % XML "INCLUDE" >
<!ENTITY % SGML "IGNORE" >
]>
.... normal XML text ...
So possibly you have to add a doctype in front.
The doctype should have an inline section with all your DTD entities and such.
Try it first by hand. Good luck.