Permalink
Browse files

CData, comments, and error callbacks

  • Loading branch information...
1 parent 4fff94f commit dd4d530fa597de761b92b5c9f397284c0e434bc4 Robert Righter committed Jan 10, 2010
Showing with 16 additions and 16 deletions.
  1. +16 −16 lib/node-xml.js
View
@@ -247,15 +247,14 @@ XMLP.prototype._parsePrefixAndElementName = function (elementlabel){
XMLP.prototype._parseNamespacesAndAtts = function (atts){
//translate namespaces into objects with "prefix","uri", "scopetag" Add them to: this.m_namespaceList
//The function should return a new list of tag attributes with the namespaces filtered
- sys = require('sys');
that = this;
var newnamespaces = [];
var filteredatts = [];
atts.map(function (item){
- if(item.name.slice(0,5) === "xmlns"){
+ if(item[0].slice(0,5) === "xmlns"){
newnamespaces.push({
- prefix : item.name.slice(6),
- uri : item.value,
+ prefix : item[0].slice(6),
+ uri : item[1],
scopetag : that.m_name,
});
}
@@ -265,13 +264,10 @@ XMLP.prototype._parseNamespacesAndAtts = function (atts){
return "not used";
});
this.m_namespaceList = this.m_namespaceList.concat(newnamespaces);
- return [filteredatts, newnamespaces.map(function(item){
- return item.prefix+","+item.uri
- }).join(',')];
+ return [ filteredatts, newnamespaces.map(function(item){return [item.prefix,item.uri];}) ];
}
XMLP.prototype._getContextualNamespace = function (prefix){
- var sys = require('sys');
if(prefix !== ''){
for(item in this.m_namespaceList){
item = this.m_namespaceList[item];
@@ -679,7 +675,7 @@ XMLP.prototype._setErr = function(iErr) {
//SaxParser is an object that basically wraps an XMLP instance, and provides an
//event-based interface for parsing. This is the object users interact with when coding
//with XML for <SCRIPT>
-this.SaxParser = function(eventhandlerfactory) {
+var SaxParser = function(eventhandlerfactory) {
var eventhandler = new function(){
@@ -839,7 +835,7 @@ SaxParser.prototype._fireError = function(strMsg) {
this.m_bErr = true;
if(this.m_hndErr && this.m_hndErr.onError) {
- this.m_hndErr.onError(this);
+ this.m_hndErr.onError(this.m_strErrMsg);
}
}
@@ -913,7 +909,7 @@ SaxParser.prototype._parseLoop = function(parser) {
iEvent = parser.next();
if(iEvent == XMLP._ELM_B) {
- theatts = this.m_parser.m_atts.map(function(item){return { name : item[0], value : item[1], };});
+ theatts = this.m_parser.m_atts;//this.m_parser.m_atts.map(function(item){return { name : item[0], value : item[1], };});
nameobject = parser._parsePrefixAndElementName(parser.getName());
theattsandnamespace = parser._parseNamespacesAndAtts(theatts);
var theuri = parser._getContextualNamespace(nameobject.prefix);
@@ -930,7 +926,7 @@ SaxParser.prototype._parseLoop = function(parser) {
this._fireEvent(SaxParser.ELM_E, parser.getName());
}
else if(iEvent == XMLP._TEXT) {
- this._fireEvent(SaxParser.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+ this._fireEvent(SaxParser.CHARS, parser.getContent().slice(parser.getContentBegin(),parser.getContentEnd()));
}
else if(iEvent == XMLP._ENTITY) {
this._fireEvent(SaxParser.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
@@ -939,12 +935,12 @@ SaxParser.prototype._parseLoop = function(parser) {
this._fireEvent(SaxParser.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
}
else if(iEvent == XMLP._CDATA) {
- this._fireEvent(SaxParser.CD_B);
- this._fireEvent(SaxParser.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
- this._fireEvent(SaxParser.CD_E);
+ this._fireEvent(SaxParser.CD_B, parser.getContent().slice(parser.getContentBegin(),parser.getContentEnd()));
+ //this._fireEvent(SaxParser.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+ //this._fireEvent(SaxParser.CD_E);
}
else if(iEvent == XMLP._COMMENT) {
- this._fireEvent(SaxParser.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
+ this._fireEvent(SaxParser.CMNT, parser.getContent().slice(parser.getContentBegin(),parser.getContentEnd()));
}
else if(iEvent == XMLP._DTD) {
}
@@ -1173,4 +1169,8 @@ function __unescapeString(str) {
return str;
}
+process.mixin(exports, {
+ SaxParser: SaxParser
+});
+
})()

0 comments on commit dd4d530

Please sign in to comment.