DOM manipulation inside the webmaster

I know that workers cannot manipulate a document directly, but what about DOM API methods? Where did they go?!

For example, if I make a request that receives an HTML fragment, then what should I do if I just need to parse it to extract some data from a particular node ?!

There is absolutely no way to work with a virtual DOM for web workers ?!

+4
source share
3 answers

Browser Support

DOMParseror document.implementationcommonly used to parse HTML in the DOM in browsers. None of them are available in a working context.

Firefox , - , DOM. : https://bugzilla.mozilla.org/show_bug.cgi?id=677123

google .

-

, , DOM XML WebWorkers, . , , JSDOM, .


DOMParser, : https://jsfiddle.net/svaqb2wn/2/

+4

, XML - XMLHttpRequest, 9 10 . - XMLHttpRequest. XML-:

https://github.com/isaacs/sax-js

http://xmljs.sourceforge.net/index.html https://www.npmjs.com/package/xmljs

HTML - XML, . xmljs npmjs :

var XmlParser = require("xmljs");
var fs = require("fs");


var p = new XmlParser({ strict: true });
var xml = fs.readFileSync("./SOAP1.xml"); // XML in the examples direct 
var xmlNode = p.parseString(xml, function(err, xmlNode) {
    if(err) {
        console.error(err);
        return;
    }
    var nodes = xmlNode.path(["Envelope", "Body", "GetstockpriceResponse", "Price"], true);
    console.log(nodes.map(function(n) { return n.text; }));
});
-1

Source: https://habr.com/ru/post/1615332/


All Articles