Comparing version 0.8.9 to 0.9.0
@@ -66,48 +66,2 @@ /*jslint node:true */ | ||
module.exports = function(xml, userOptions) { | ||
var parser = pureJsParser ? sax.parser(true, {}) : parser = new expat.Parser('UTF-8'); | ||
var result = {}; | ||
currentElement = result; | ||
options = validateOptions(userOptions); | ||
if (pureJsParser) { | ||
parser.onopentag = onStartElement; | ||
parser.ontext = onText; | ||
parser.oncomment = onComment; | ||
parser.onclosetag = onEndElement; | ||
parser.onerror = onError; | ||
parser.oncdata = onCdata; | ||
parser.onprocessinginstruction = onDeclaration; | ||
} else { | ||
parser.on('startElement', onStartElement); | ||
parser.on('text', onText); | ||
parser.on('comment', onComment); | ||
parser.on('endElement', onEndElement); | ||
parser.on('error', onError); | ||
//parser.on('startCdata', onStartCdata); | ||
//parser.on('endCdata', onEndCdata); | ||
//parser.on('entityDecl', onEntityDecl); | ||
} | ||
if (pureJsParser) { | ||
parser.write(xml).close(); | ||
} else { | ||
if (!parser.parse(xml)) { | ||
throw new Error('XML parsing error: ' + parser.getError()); | ||
} | ||
} | ||
if (result[options.elementsKey]) { | ||
var temp = result[options.elementsKey]; | ||
delete result[options.elementsKey]; | ||
result[options.elementsKey] = temp; | ||
delete result.text; | ||
} | ||
return result; | ||
}; | ||
function onDeclaration (declaration) { | ||
@@ -243,2 +197,48 @@ if (options.ignoreDeclaration) { | ||
console.error('error', error); | ||
} | ||
} | ||
module.exports = function(xml, userOptions) { | ||
var parser = pureJsParser ? sax.parser(true, {}) : parser = new expat.Parser('UTF-8'); | ||
var result = {}; | ||
currentElement = result; | ||
options = validateOptions(userOptions); | ||
if (pureJsParser) { | ||
parser.onopentag = onStartElement; | ||
parser.ontext = onText; | ||
parser.oncomment = onComment; | ||
parser.onclosetag = onEndElement; | ||
parser.onerror = onError; | ||
parser.oncdata = onCdata; | ||
parser.onprocessinginstruction = onDeclaration; | ||
} else { | ||
parser.on('startElement', onStartElement); | ||
parser.on('text', onText); | ||
parser.on('comment', onComment); | ||
parser.on('endElement', onEndElement); | ||
parser.on('error', onError); | ||
//parser.on('startCdata', onStartCdata); | ||
//parser.on('endCdata', onEndCdata); | ||
//parser.on('entityDecl', onEntityDecl); | ||
} | ||
if (pureJsParser) { | ||
parser.write(xml).close(); | ||
} else { | ||
if (!parser.parse(xml)) { | ||
throw new Error('XML parsing error: ' + parser.getError()); | ||
} | ||
} | ||
if (result[options.elementsKey]) { | ||
var temp = result[options.elementsKey]; | ||
delete result[options.elementsKey]; | ||
result[options.elementsKey] = temp; | ||
delete result.text; | ||
} | ||
return result; | ||
}; |
{ | ||
"name": "xml-js", | ||
"version": "0.8.9", | ||
"version": "0.9.0", | ||
"description": "A convertor between XML text and Javascript object / JSON text.", | ||
@@ -59,3 +59,2 @@ "main": "index.js", | ||
"rimraf": "^2.5.2", | ||
"watchify": "latest", | ||
"watch": "^0.18.0" | ||
@@ -62,0 +61,0 @@ }, |
@@ -17,3 +17,3 @@ ![XML ⇔ JS/JSON](http://nashwaan.github.io/xml-js/images/logo.svg) | ||
[![Dependency Status](https://david-dm.org/nashwaan/xml-js.svg)](https://david-dm.org/nashwaan/xml-js) | ||
[![Package Quality](http://xxxnpm.packagequality.com/shield/xml-js.svg)](http://packagequality.com/#?package=xml-js) | ||
[![Package Quality](http://xxxnpm.packagequality.com/shield/xml-js.svg)](http://xxxpackagequality.com/#?package=xml-js) | ||
@@ -20,0 +20,0 @@ # Synopsis |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
1371349