Thanks for the tip about appending strings creating new string instances. I didn't know that. 

Yeah, I think the performance of this could probably be increased a lot. For one thing, I'm not sure the DOMParser package is very fast for what I am doing.