Parsing XML in Web Workers

前端 未结 1 929
耶瑟儿~
耶瑟儿~ 2020-12-16 03:02

I know the Web Worker spec says \"no access to DOM because DOM is not thread safe\". While I can see that\'s logical for web workers and the HTML page DOM, it\'s actually ve

相关标签:
1条回答
  • 2020-12-16 03:24

    Um - answering myself a few hours later - but this may well be a piece of information that proves very useful to people:

    There IS an open-source, full function XML parser written entirely in javascript - and it works very well in Web Workers:

    XML-JS

    Basically, you just need to include tinyxmlsax.js and tinyxmlw3cdom.js in your worker, then follow the doc for using the W3C DOM.

    With very little massaging, I got my code to work with both the normal DOMParser (for when running in the foreground) and the xmljs parser.

    Obviously its slower - but that really isn't too much of an issue - after all, you're running it in the background!

    0 讨论(0)
提交回复
热议问题