// Workaround for broken XML parser in node.js/jquery
// see https://github.com/coolaj86/node-jquery/issues/29
-
var jsdom = require("jsdom");
var DOMParser = require('xmldom').DOMParser;
-var xmlstring = '<?xml version="1.0" encoding="UTF-8"?><process>yes</process>';
+var xmlstring = '<?xml version="1.0" encoding="UTF-8"?><process>yes</process>';
+
+jsdom.env('<html/>',
+// ["http://code.jquery.com/jquery.js"],
-jsdom.env(
- '<html/>',
- // ["http://code.jquery.com/jquery.js"],
- function (errors, window) {
- // var $ = window.$;
- var $ = require('jQuery');
- // override jquery xml parser with external XML lib xmldoc.DOMParser
- $.parseXML = function(data) { return new DOMParser().parseFromString(data) };;
+function (errors, window) {
+ // var $ = window.$;
+ var $ = require('jQuery');
- // parse XML string, extract "process" node and keep the text value of the node
- var result = $( $.parseXML(xmlstring)).find("process").text();
+ // override jquery xml parser with external XML lib xmldoc.DOMParser
+ $.parseXML = function (data) {
+ return new DOMParser().parseFromString(data)
+ };;
- // should output "yes"
- console.log("Testing jsdom/xmldom/jQuery $.parseXML() support: " + result);
- }
-);
+ // parse XML string, extract "process" node and keep the text value of the node
+ var result = $($.parseXML(xmlstring)).find("process").text();
+ // should output "yes"
+ console.log("Testing jsdom/xmldom/jQuery $.parseXML() support: " + result);
+});
-describe("jsdom/jQuery suite simple", function() {
- it("jsdom test", function() {
+describe("jsdom/jQuery suite simple", function () {
+ it("jsdom test", function () {
var jsdom = require("jsdom");
- var $, w;
- jsdom.env('<p><a class="the-link" href="http://indexdata.com">jsdom\'s Homepage</a></p>', ["http://code.jquery.com/jquery.js"], function(errors, window) {
+ var $, w;
+ jsdom.env('<p><a class="the-link" href="http://indexdata.com">jsdom\'s Homepage</a></p>', ["http://code.jquery.com/jquery.js"], function (errors, window) {
console.log("contents of a.the-link:", window.$("a.the-link").text());
- w = window;
+ w = window;
$ = window.$;
});
- waitsFor(function() {
+ waitsFor(function () {
if (!w) {
- console.log(".");
- }
+ console.log(".");
+ }
return w;
}, "window object done", 2 * 1000);
- runs(function() {
+ runs(function () {
console.log("got window");
expect(w).toBeDefined();
expect(w.document).toBeDefined();
var xmlstring = "<rss version='2.0' jsessionId='CD8AFDD3040A81CFFDDD4EC066497139'><channel><title>RSS Title</title></channel></rss>";
- var DOMParser = require('xmldom').DOMParser;
- var doc = new DOMParser().parseFromString(xmlstring);
- console.log("doc: " + doc.documentElement.getAttribute('jsessionId'));
+ var DOMParser = require('xmldom').DOMParser;
+ var doc = new DOMParser().parseFromString(xmlstring);
+ console.log("doc: " + doc.documentElement.getAttribute('jsessionId'));
var xmlDoc = doc; // $.parseXML(xml);
- var xml = $(xmlDoc);
- var title = xml.find("title");
+ var xml = $(xmlDoc);
+ var title = xml.find("title");
- console.log("title: " + $(title).text() );
- $.parseXML = function (data) { return new DOMParser().parseFromString(data) };;
+ console.log("title: " + $(title).text());
+ $.parseXML = function (data) {
+ return new DOMParser().parseFromString(data)
+ };;
- console.log("parseXML: " + $( $.parseXML( xmlstring)).text() );
+ console.log("parseXML: " + $($.parseXML(xmlstring)).text());
- // console.log(w.document);
+ // console.log(w.document);
})
});