3

Is it possible to load an XML / HTML document with node.js and perform operations such as getElementsByTagName ?

3 Answers 3

4

node.js doesn't give you a DOM "out of the box", but there is a great module that provides a proper HTML DOM: https://github.com/tmpvar/jsdom.


Edit: there are also several modules that help with interacting with XML. Here's a list of them on the wiki (this page is deprecated): https://github.com/joyent/node/wiki/modules#wiki-parsers-xml

Sign up to request clarification or add additional context in comments.

Comments

3

Cheerio: Tiny, fast, and elegant implementation of core jQuery designed specifically for the server.

var cheerio = require('cheerio'),
    $ = cheerio.load('<h2 class="title">Hello world</h2>');

$('h2.title').text('Hello there!');
$('h2').addClass('welcome');

$.html();
//=> <h2 class="title welcome">Hello there!</h2> 

1 Comment

This is the best answer here if you're wanting to query HTML.
0

Also check out https://github.com/robtweed/ewdDOM

This is a persistent DOM implementation using the Globals database

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.