Permalink
Browse files

API change.

Tag events don't really need the node name parameter  so we only pass the attributes.
  • Loading branch information...
1 parent 8661197 commit 01e8c64606a287732b0f1bf6b515f57b0e28c3e4 @lucsky committed Oct 5, 2013
Showing with 28 additions and 23 deletions.
  1. +1 −1 lib/exml.js
  2. +1 −1 package.json
  3. +1 −1 test/fixtures/simple.xml
  4. +25 −20 test/test.js
View
@@ -37,7 +37,7 @@ Parser.prototype._handleOpenTag = function(node) {
this._frameStack.push(_newFrame());
if (handler) {
- handler(node.name, node.attributes);
+ handler(node.attributes);
}
};
View
@@ -1,6 +1,6 @@
{
"name": "exml",
- "version": "0.1.0",
+ "version": "0.2.0",
"description": "An event based XML parsing library using SAX under the hood for speed and efficiency.",
"keywords": ["xml", "events"],
"author": "Luc Heinrich <luc@honk-honk.com>",
View
@@ -4,6 +4,6 @@
<node attr1="node2.attr1" attr2="node2.attr2" />
<node attr1="node3.attr1" attr2="node3.attr2" />
<node attr1="node4.attr1" attr2="node4.attr2">
- <subnode />
+ <subnode attr1="subnode.attr1" attr2="subnode.attr2" />
</node>
</root>
View
@@ -14,18 +14,17 @@ module.exports['node events'] = {
'local': function(test) {
var parser = this.parser;
- parser.on('root', function(name, attributes) {
- test.equal(name, 'root');
+ parser.on('root', function(attributes) {
test.equal(attributes.attr1, 'root.attr1');
test.equal(attributes.attr2, 'root.attr2');
var nodeIndex = 1;
- parser.on('node', function(name, attributes) {
- test.equal(name, 'node');
+ parser.on('node', function(attributes) {
test.equal(attributes.attr1, 'node' + nodeIndex + '.attr1');
test.equal(attributes.attr2, 'node' + nodeIndex + '.attr2');
nodeIndex++;
- parser.on('subnode', function(name) {
- test.equal(name, 'subnode');
+ parser.on('subnode', function(attributes) {
+ test.equal(attributes.attr1, 'subnode.attr1');
+ test.equal(attributes.attr2, 'subnode.attr2');
});
});
});
@@ -35,22 +34,21 @@ module.exports['node events'] = {
},
'stacked': function(test) {
- this.parser.on('root', function(name, attributes) {
- test.equal(name, 'root');
+ this.parser.on('root', function(attributes) {
test.equal(attributes.attr1, 'root.attr1');
test.equal(attributes.attr2, 'root.attr2');
});
var nodeIndex = 1;
- this.parser.on('root', 'node', function(name, attributes) {
- test.equal(name, 'node');
+ this.parser.on('root', 'node', function(attributes) {
test.equal(attributes.attr1, 'node' + nodeIndex + '.attr1');
test.equal(attributes.attr2, 'node' + nodeIndex + '.attr2');
nodeIndex++;
});
- this.parser.on('root', 'node', 'subnode', function(name) {
- test.equal(name, 'subnode');
+ this.parser.on('root', 'node', 'subnode', function(attributes) {
+ test.equal(attributes.attr1, 'subnode.attr1');
+ test.equal(attributes.attr2, 'subnode.attr2');
});
this.parser.end(SIMPLE_XML);
@@ -59,10 +57,14 @@ module.exports['node events'] = {
'partially stacked 1': function(test) {
var parser = this.parser;
- parser.on('root', 'node', function(name, attributes) {
- test.equal(name, 'node');
- parser.on('subnode', function(name) {
- test.equal(name, 'subnode');
+ var nodeIndex = 1;
+ parser.on('root', 'node', function(attributes) {
+ test.equal(attributes.attr1, 'node' + nodeIndex + '.attr1');
+ test.equal(attributes.attr2, 'node' + nodeIndex + '.attr2');
+ nodeIndex++;
+ parser.on('subnode', function(attributes) {
+ test.equal(attributes.attr1, 'subnode.attr1');
+ test.equal(attributes.attr2, 'subnode.attr2');
});
});
@@ -72,10 +74,13 @@ module.exports['node events'] = {
'partially stacked 2': function(test) {
var parser = this.parser;
- parser.on('root', function(name, attributes) {
- test.equal(name, 'root');
- parser.on('node', 'subnode', function(name) {
- test.equal(name, 'subnode');
+ parser.on('root', function(attributes) {
+ test.equal(attributes.attr1, 'root.attr1');
+ test.equal(attributes.attr2, 'root.attr2');
+ var nodeIndex = 1;
+ parser.on('node', 'subnode', function(attributes) {
+ test.equal(attributes.attr1, 'subnode.attr1');
+ test.equal(attributes.attr2, 'subnode.attr2');
});
});

0 comments on commit 01e8c64

Please sign in to comment.