在Web工作人员中解析XML [英] Parsing XML in Web Workers

查看:126
本文介绍了在Web工作人员中解析XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Web Worker规范说不能访问DOM,因为DOM不是线程安全的。虽然我可以看到这对于web worker和HTML页面DOM来说是合乎逻辑的,但是在考虑从XmlHttpRequest调用中解析XML时,实际上是非常有限制的 - 毕竟,该调用的基本处理是异步的,因此对前台线程影响不大解析XML减慢前景线程(处理XML应用程序时)。

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 very restrictive when considering parsing XML from an XmlHttpRequest call - after all, the basic handling of that call is asynchronous and so has little effect on the foreground thread, it's the parsing of the XML that slows down the foreground thread (when dealing with XML apps).

除了在Javascript中构建我自己的XML解析器,我有什么办法(我'不要去XPCOM路线!)在Web Worker中解析XML?

Is there any way other than building my own XML parser in Javascript (I'm not going the XPCOM route!) to parse XML in the Web Worker?

推荐答案

我在几个小时后回答自己 - 但这可能是一个证明对人们非常有用的信息:

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

这是一个完全用JavaScript编写的开放源码的全功能XML解析器,它的作品非常好的网络工作者:

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

XML-JS

基本上,您只需要包含tinyxmlsax。 js和tinyxmlw3cdom.js,然后按照文档使用W3C DOM。

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

只需很少的按摩功能,我的代码就可以正常使用DOMParser (对于在前台运行)和xmljs解析器。

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!

这篇关于在Web工作人员中解析XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆