-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
41 lines (29 loc) · 1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function() {
var halfstreamxml, onerror, onfinishparser, onfinishstream, parser, stream, wantednodes, xml;
halfstreamxml = require('./index');
onerror = function(e) {
return console.error("ERROR: " + e);
};
onfinishparser = function() {
return console.log("PARSER TEST DONE\n");
};
onfinishstream = function() {
return console.log("STREAM TEST DONE\n");
};
wantednodes = {
PERSON: function(person) {
var str;
str = JSON.stringify({
name: person.children.tags.NAME[0].children.text.join(),
age: person.attributes.age
});
return console.log("received person: " + str);
}
};
xml = '<xml><person age="15"><name>Barfoo</name></person><person age="17"><name>Foo Bar</name></person></xml>';
parser = halfstreamxml.createParser(onerror, onfinishparser, wantednodes, false);
stream = halfstreamxml.createStream(onerror, onfinishstream, wantednodes, false);
parser.write(xml).close();
stream.write(xml);
stream.end();
}).call(this);