Permalink
Browse files

adding strict switch from sax to DomJS

  • Loading branch information...
1 parent 9fa3b12 commit ee7c8636d95a65464954e7c00a35526570a07e84 @teknopaul committed Mar 7, 2012
Showing with 25 additions and 3 deletions.
  1. +23 −0 example/test-strict-switch.js
  2. +2 −3 lib/dom-js.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
View
@@ -1,5 +1,4 @@
var sax = require("sax");
-var strict = true;
/**
* Really simple XML DOM implementation based on sax that works with Strings.
@@ -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) {
@@ -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;
@@ -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.