forked from robrighter/node-xml
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Righter
committed
Jan 10, 2010
1 parent
dd4d530
commit beedf7f
Showing
3 changed files
with
171 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,39 @@ | ||
var sys = require('sys'); | ||
var posix = require('posix'); | ||
var xml = require("./lib/node-xml"); | ||
|
||
var parser = new SAXDriver(); | ||
|
||
parser.setDocumentHandler({ | ||
startElement : function(name, atts) { | ||
sys.puts("=> Started: " + name + " (Attributes: " + JSON.stringify(atts) + " )"); | ||
}, | ||
|
||
endElement : function(name) { | ||
sys.puts("<= End: " + name + "\n"); | ||
parser.pause();// pause the parser | ||
setTimeout(function (){parser.resume();}, 200); //resume the parser | ||
} | ||
}); | ||
|
||
parser.setErrorHandler({ | ||
error : function(exception) { | ||
sys.puts("ERROR: " +exception.getMessage()); | ||
}, | ||
var parser = new xml.SaxParser(function(cb) { | ||
cb.onStartDocument(function() { | ||
sys.puts('DOCUMENT STARTED'); | ||
}); | ||
cb.onEndDocument(function() { | ||
sys.puts('DOCUMENT ENDED'); | ||
}); | ||
cb.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) { | ||
sys.puts("=> Started: " + elem + " uri="+uri +" (Attributes: " + JSON.stringify(attrs) + " )"); | ||
}); | ||
cb.onEndElementNS(function(elem, prefix, uri) { | ||
sys.puts("<= End: " + elem + " uri="+uri + "\n"); | ||
parser.pause();// pause the parser | ||
setTimeout(function (){parser.resume();}, 200); //resume the parser | ||
}); | ||
cb.onCharacters(function(chars) { | ||
//sys.puts('<CHARS>'+chars+"</CHARS>"); | ||
}); | ||
cb.onCdata(function(cdata) { | ||
sys.puts('<CDATA>'+cdata+"</CDATA>"); | ||
}); | ||
cb.onComment(function(msg) { | ||
sys.puts('<COMMENT>'+msg+"</COMMENT>"); | ||
}); | ||
cb.onWarning(function(msg) { | ||
sys.puts('<WARNING>'+msg+"</WARNING>"); | ||
}); | ||
cb.onError(function(msg) { | ||
sys.puts('<ERROR>'+JSON.stringify(msg)+"</ERROR>"); | ||
}); | ||
|
||
posix.cat("sample.xml").addCallback(function (content) { | ||
sys.puts('...starting parsing'); | ||
parser.parse(content); | ||
}); | ||
|
||
parser.parseFile("sample.xml"); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters