Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

responseXML implementation using jsdom (htmlparser) #19

Open
lordbaco opened this Issue Jan 11, 2012 · 1 comment

Comments

Projects
None yet
2 participants

Hello,

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

Related to
#8
#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 :
lordbaco/node-XMLHttpRequest@1303a25

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<nodes.length; i++) {
// ...
sys.print(nodes[i].nodeName.toLowerCase() + "\n");
}
}
};
xhr.open("GET", url);
xhr.send();

Best Regards,
Guy (Lordbaco)

Owner

driverdan commented Feb 20, 2012

Sorry about the late response. Can you issue a pull request? That way I can implement it with proper attribution and can modify a few items before accepting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment