Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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>'+chars+"</CHARS>");
//console.log('<CHARS>'+chars+"</CHARS>");
});
cb.onCdata(function(cdata) {
util.log('<CDATA>'+cdata+"</CDATA>");
console.log('<CDATA>'+cdata+"</CDATA>");
});
cb.onComment(function(msg) {
util.log('<COMMENT>'+msg+"</COMMENT>");
console.log('<COMMENT>'+msg+"</COMMENT>");
});
cb.onWarning(function(msg) {
util.log('<WARNING>'+msg+"</WARNING>");
console.log('<WARNING>'+msg+"</WARNING>");
});
cb.onError(function(msg) {
util.log('<ERROR>'+JSON.stringify(msg)+"</ERROR>");
console.log('<ERROR>'+JSON.stringify(msg)+"</ERROR>");
});
});

Expand Down
15 changes: 7 additions & 8 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var util = require('util');
var xml = require("./lib/node-xml");

var parser = new xml.SaxParser(function(cb) {
Expand All @@ -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>'+chars+"</CHARS>");
console.log('<CHARS>'+chars+"</CHARS>");
});
cb.onCdata(function(cdata) {
util.log('<CDATA>'+cdata+"</CDATA>");
console.log('<CDATA>'+cdata+"</CDATA>");
});
cb.onComment(function(msg) {
util.log('<COMMENT>'+msg+"</COMMENT>");
console.log('<COMMENT>'+msg+"</COMMENT>");
});
cb.onWarning(function(msg) {
util.log('<WARNING>'+msg+"</WARNING>");
console.log('<WARNING>'+msg+"</WARNING>");
});
cb.onError(function(msg) {
util.log('<ERROR>'+JSON.stringify(msg)+"</ERROR>");
console.log('<ERROR>'+JSON.stringify(msg)+"</ERROR>");
});
});

Expand Down
11 changes: 0 additions & 11 deletions lib/node-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -795,17 +794,7 @@ 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.parseString = function(strD) {
util = require('util');
var that = this;
var startnew = true;
if(!that.m_parser){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"type" : "git",
"url" : "git://github.com/robrighter/node-xml.git"
}
}
}