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).
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?
XML parser is a software library or a package that provides interface for client applications to work with XML documents. It checks for proper format of the XML document and may also validate the XML documents. Modern day browsers have built-in XML parsers. The goal of a parser is to transform XML into a readable code.
The application receives document information from the parser through a ContentHandler object. It implements various event handlers in the interface methods in ContentHandler, and registers the ContentHandler object with the SAX parser. The parser reads an XML document from the beginning to the end.
All major browsers have a built-in XML parser to access and manipulate XML.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With