Skip to content

Commit

Permalink
Adding a test to illustrate how to get the root element.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoramite committed Jun 13, 2012
1 parent 4bbdfc1 commit 860a504
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/fixture/input01.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<example> <example foo="bar">
<animals> <animals>
<dog name="Fluffy"/> <dog name="Fluffy"/>
<dog name="Max"/> <dog name="Max"/>
Expand Down
23 changes: 23 additions & 0 deletions test/root-test.js
@@ -0,0 +1,23 @@
var nodeunit = require('nodeunit');
var path = require('path');
var xml2object = require('../lib/xml2object');

exports.testRoot = function(test){
test.expect(2);

var parser = new xml2object(['example'], path.normalize(__dirname + '/fixture/input01.xml'));
var found = [];

parser.on('object', function(name, obj) {
found.push(obj.foo);
});

parser.on('end', function() {
test.equal(found.length, 1, "Should have found two objects");
test.equal(found[0], 'bar', 'foobar mismatch');

test.done();
});

parser.start();
};

0 comments on commit 860a504

Please sign in to comment.