We propose a new technique based on recursive finite state machines, for tracking context to be used in a statistical code compression scheme for XML documents. An arithmetic coding scheme [1] is used for this purpose. We also study the tradeoffs between space and compression ratio, by observing the effects of either using or ignoring root to leaf contexts for textual content in the associated tree structures.