libxml-to-js
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -0,1 +1,4 @@ | ||
## v0.3.6 | ||
* Fixes [#5](https://github.com/SaltwaterC/libxml-to-js/pull/5) which was introduced in v0.3.5. | ||
## v0.3.5 | ||
@@ -2,0 +5,0 @@ * Improved the text kludge and namespaces support. Thanks to @[VirgileD](https://github.com/VirgileD) for the contribution. |
@@ -151,8 +151,11 @@ var libxmljs = require('libxmljs'); | ||
} | ||
var xmlDocument, jsDocument, selected = []; | ||
var xmlDocument, jsDocument, selected = [], xmlns = null; | ||
try { | ||
xmlDocument = libxmljs.parseXmlString(xml); | ||
jsDocument = libxml2js(xmlDocument); | ||
if( jsDocument['@'] && jsDocument['@'].xmlns) { | ||
xmlns = jsDocument['@'].xmlns; | ||
} | ||
if( !! xpath) { | ||
xmlDocument.find(xpath, jsDocument['@'].xmlns).forEach(function(item) { | ||
xmlDocument.find(xpath, xmlns).forEach(function(item) { | ||
selected.push(libxml2js(item, true).jsobj); | ||
@@ -159,0 +162,0 @@ }); |
{ | ||
"name": "libxml-to-js", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"main": "./lib/libxml-to-js.js", | ||
@@ -5,0 +5,0 @@ "description": "XML to JavaScript object parser based on libxmljs", |
@@ -6,3 +6,7 @@ var parser = require('../'); | ||
var callback = false; | ||
var callbackXPath = false; | ||
parser(fs.readFileSync('data/text.xml').toString(), function (err, res) { | ||
callback = true; | ||
assert.ifError(err); | ||
@@ -38,1 +42,17 @@ assert.deepEqual({ | ||
}); | ||
parser(fs.readFileSync('data/text.xml').toString(), '//nouvelle/news', function (err, res) { | ||
callbackXPath = true; | ||
assert.ifError(err); | ||
assert.deepEqual({ | ||
"auteur": "Bizzard5", | ||
"date": "17 Août 2008", | ||
"text": {} | ||
}, | ||
res[0]); | ||
}); | ||
process.on('exit', function () { | ||
assert.ok(callback); | ||
assert.ok(callbackXPath); | ||
}); |
66940
299