Skip to content

Commit

Permalink
API change.
Browse files Browse the repository at this point in the history
Tag events don't really need the node name parameter  so we only pass the attributes.
  • Loading branch information
lucsky committed Oct 5, 2013
1 parent 8661197 commit 01e8c64
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/exml.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Parser.prototype._handleOpenTag = function(node) {
this._frameStack.push(_newFrame());

if (handler) {
handler(node.name, node.attributes);
handler(node.attributes);
}
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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>",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/simple.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
45 changes: 25 additions & 20 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Expand All @@ -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);
Expand All @@ -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');
});
});

Expand All @@ -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');
});
});

Expand Down

0 comments on commit 01e8c64

Please sign in to comment.