author and iconoclast
This is a very complicated description; so complicated, in fact, that I doubt many people can understand it -- I certainly can't. I wonder how much of what you're saying here is part of your requirements, and how much is actually part of your guess at an implementation. I suspect there is some of each.
Why not reply to my message with a clear, short statement of just the requirements you're trying to fulfill. Don't say anything about XML, HTML, or any other technical stuff. Just tell us exactly what you are being asked to do, and nothing more. Then perhaps someone will be able to recommend an approach.