when moving all this in a worker, you'll want to use the library from http://ejohn.org/blog/pure-javascript-html-parser/
we use it in email and it works fine, at least for HTML, but I suspect it works for XML too.
please put the library in `/shared/js` as we'll need it in other apps too.