Skip to content

Commit

Permalink
adding strict switch from sax to DomJS
Browse files Browse the repository at this point in the history
  • Loading branch information
teknopaul committed Mar 7, 2012
1 parent 9fa3b12 commit ee7c863
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
23 changes: 23 additions & 0 deletions example/test-strict-switch.js
@@ -0,0 +1,23 @@
var util = require('util');
var DomJS = require("dom-js").DomJS;

var domjs = new DomJS();
/**
* Not sure why any one would want to do this, but request comes from eddyb
* Set strict to false, the XML elements all come out in UPPERCASE.
* If that is a "feature" its a weird one! I think strict is mean to be about namespaces.
*/
domjs.strict = false;

console.log("\nExample XML");
var string = '<?xml version="1.0" encoding="UTF-8"?>' +
'<xml>' +
'<a>a</a>' +
'<!-- the comment --><elem someAtt="fat &amp; red">Hello &quot;World&quot;</elem><elem otherAtt="val1"/><elem lastAtt="val1"/></xml>';
console.log(string);
domjs.parse(string, function(err, dom) {
console.log(util.inspect(dom, false, 23));
console.log("serializes to : " + dom.toXml());
});

domjs.reset(); //before reuse
5 changes: 2 additions & 3 deletions lib/dom-js.js
@@ -1,5 +1,4 @@
var sax = require("sax");
var strict = true;

/**
* Really simple XML DOM implementation based on sax that works with Strings.
Expand Down Expand Up @@ -42,6 +41,7 @@ var DomJS = function() {
this.stack = new Array();
this.currElement = null;
this.error = false;
this.strict = true;
};

DomJS.prototype.parse = function(string, cb) {
Expand All @@ -50,7 +50,7 @@ DomJS.prototype.parse = function(string, cb) {
return;
}
var self = this;
var parser = sax.parser(strict);
var parser = sax.parser(this.strict);

parser.onerror = function (err) {
self.error = true;
Expand Down Expand Up @@ -193,4 +193,3 @@ exports.Comment = Comment;
exports.CDATASection = CDATASection;
exports.DomJS = DomJS;
exports.escape = escape;

0 comments on commit ee7c863

Please sign in to comment.