From 927eb339ebc5a22a72de252dac4c606e8c63f32a Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Fri, 19 May 2017 14:39:26 +0100 Subject: [PATCH 1/3] Remove util dependency --- README.md | 15 +++++++-------- example.js | 15 +++++++-------- lib/node-xml.js | 2 -- package.json | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b3b01e1..f655777 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,6 @@ Called when an error is encountered EXAMPLE USAGE ------------- - var util = require('util'); var xml = require("./lib/node-xml"); var parser = new xml.SaxParser(function(cb) { @@ -126,27 +125,27 @@ EXAMPLE USAGE }); cb.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) { - util.log("=> Started: " + elem + " uri="+uri +" (Attributes: " + JSON.stringify(attrs) + " )"); + console.log("=> Started: " + elem + " uri="+uri +" (Attributes: " + JSON.stringify(attrs) + " )"); }); cb.onEndElementNS(function(elem, prefix, uri) { - util.log("<= End: " + elem + " uri="+uri + "\n"); + console.log("<= End: " + elem + " uri="+uri + "\n"); parser.pause();// pause the parser setTimeout(function (){parser.resume();}, 200); //resume the parser }); cb.onCharacters(function(chars) { - //util.log(''+chars+""); + //console.log(''+chars+""); }); cb.onCdata(function(cdata) { - util.log(''+cdata+""); + console.log(''+cdata+""); }); cb.onComment(function(msg) { - util.log(''+msg+""); + console.log(''+msg+""); }); cb.onWarning(function(msg) { - util.log(''+msg+""); + console.log(''+msg+""); }); cb.onError(function(msg) { - util.log(''+JSON.stringify(msg)+""); + console.log(''+JSON.stringify(msg)+""); }); }); diff --git a/example.js b/example.js index 654c999..9fde39f 100755 --- a/example.js +++ b/example.js @@ -1,4 +1,3 @@ -var util = require('util'); var xml = require("./lib/node-xml"); var parser = new xml.SaxParser(function(cb) { @@ -9,27 +8,27 @@ var parser = new xml.SaxParser(function(cb) { }); cb.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) { - util.log("=> Started: " + elem + " uri="+uri +" (Attributes: " + JSON.stringify(attrs) + " )"); + console.log("=> Started: " + elem + " uri="+uri +" (Attributes: " + JSON.stringify(attrs) + " )"); }); cb.onEndElementNS(function(elem, prefix, uri) { - util.log("<= End: " + elem + " uri="+uri + "\n"); + console.log("<= End: " + elem + " uri="+uri + "\n"); parser.pause();// pause the parser setTimeout(function (){parser.resume();}, 100); //resume the parser }); cb.onCharacters(function(chars) { - util.log(''+chars+""); + console.log(''+chars+""); }); cb.onCdata(function(cdata) { - util.log(''+cdata+""); + console.log(''+cdata+""); }); cb.onComment(function(msg) { - util.log(''+msg+""); + console.log(''+msg+""); }); cb.onWarning(function(msg) { - util.log(''+msg+""); + console.log(''+msg+""); }); cb.onError(function(msg) { - util.log(''+JSON.stringify(msg)+""); + console.log(''+JSON.stringify(msg)+""); }); }); diff --git a/lib/node-xml.js b/lib/node-xml.js index 180a482..c49b6bd 100755 --- a/lib/node-xml.js +++ b/lib/node-xml.js @@ -480,7 +480,6 @@ XMLP.prototype._parseDTD = function(iB) { } XMLP.prototype._parseElement = function(iB) { - util = require('util'); var iE, iDE, iNE, iRet; var iType, strN, iLast; @@ -805,7 +804,6 @@ SaxParser.prototype.parseFile = function(filename) { //This function will only w SaxParser.prototype.parseString = function(strD) { - util = require('util'); var that = this; var startnew = true; if(!that.m_parser){ diff --git a/package.json b/package.json index 7807ad7..627dea4 100644 --- a/package.json +++ b/package.json @@ -18,4 +18,4 @@ "type" : "git", "url" : "git://github.com/robrighter/node-xml.git" } -} \ No newline at end of file +} From a734fcd3c242c816cd6709c85c254a1be554066c Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Fri, 19 May 2017 14:54:18 +0100 Subject: [PATCH 2/3] Comment out node-specific method --- lib/node-xml.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/node-xml.js b/lib/node-xml.js index c49b6bd..fe2b605 100755 --- a/lib/node-xml.js +++ b/lib/node-xml.js @@ -794,13 +794,15 @@ SaxParser.CMNT = 9; SaxParser.DTD_B = 10; SaxParser.DTD_E = 11; -SaxParser.prototype.parseFile = function(filename) { //This function will only work in the node.js environment. - var fs = require('fs'); - var that = this; - fs.readFile(filename, function (err, data) { - that.parseString(data); - }); -} +// SaxParser.prototype.parseFile = function(filename) { //This function will only work in the node.js environment. +// var fs = require('fs'); +// if (fs) { +// var that = this; +// fs.readFile(filename, function (err, data) { +// that.parseString(data); +// }); +// } +// } SaxParser.prototype.parseString = function(strD) { From f129038e75be34a777524168592649843c2895bc Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Fri, 19 May 2017 15:11:04 +0100 Subject: [PATCH 3/3] Remove node-specific method --- lib/node-xml.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lib/node-xml.js b/lib/node-xml.js index fe2b605..e58f3ec 100755 --- a/lib/node-xml.js +++ b/lib/node-xml.js @@ -794,17 +794,6 @@ SaxParser.CMNT = 9; SaxParser.DTD_B = 10; SaxParser.DTD_E = 11; -// SaxParser.prototype.parseFile = function(filename) { //This function will only work in the node.js environment. -// var fs = require('fs'); -// if (fs) { -// var that = this; -// fs.readFile(filename, function (err, data) { -// that.parseString(data); -// }); -// } -// } - - SaxParser.prototype.parseString = function(strD) { var that = this; var startnew = true;