driverdan/node-XMLHttpRequest — Issue #19: responseXML implementation using jsdom (htmlparser)
Author: lordbaco
Created: 2012-01-11 20:41:35+00:00
State: open

Hello,

Is is possible to include my implementation of responseXML into your
mainstream git ?

Related to
https://github.com/driverdan/node-XMLHttpRequest/issues/8
https://github.com/driverdan/node-XMLHttpRequest/issues/13

I implemented responseXML in my fork of node-XMLHttpRequest
using "jsdom" (using "htmlparser"). The benefit is that you can parse
non XML url like any HTML website and get a DOM.

I implemented it within an exception handler so node-XMLHttpRequest
should continue to work even if jsdom has not been installed. Of
course without those modules responseXML cannot be used but
responseText will continue to work.

The implementation :
https://github.com/lordbaco/node-XMLHttpRequest/commit/1303a2596ad7fad504a1e1d4c696ee76b78c6d9a

I am not sure my implementation will work with sync but async is working.

To use this feature you need to :
npm install jsdom
git clone https://lordbaco@github.com/lordbaco/node-XMLHttpRequest.git
then use it in your code

var sys = require('util');
var XMLHttpRequest = require("./node-XMLHttpRequest/XMLHttpRequest").XMLHttpRequest;
var url = 'https://github.com';
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState == 4) {
var document = this.responseXML;
//sys.puts("XML:\n" + sys.inspect(document.innerHTML, false, null));
var nodes = document.body.getElementsByTagName('*');
for (var i=0; i