Browse files

Adding a test to illustrate how to get the root element.

  • Loading branch information...
1 parent 4bbdfc1 commit 860a5047fef9e4ba509d81dbcf5499c74b58425d @Zoramite Zoramite committed Jun 13, 2012
Showing with 24 additions and 1 deletion.
  1. +1 −1 test/fixture/input01.xml
  2. +23 −0 test/root-test.js
View
2 test/fixture/input01.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<example>
+<example foo="bar">
<animals>
<dog name="Fluffy"/>
<dog name="Max"/>
View
23 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.