I'm worried this is brittle.  What if the mathml content contains, for example, a less-than-sign?  In that case, I think you'd get invalid markup.
Did you try to test this?  I haven't checked in a while, but I'm pretty sure at least one of our samples has mathml.