-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.coffee
More file actions
25 lines (20 loc) · 729 Bytes
/
test.coffee
File metadata and controls
25 lines (20 loc) · 729 Bytes
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
halfstreamxml = require './index'
onerror = (e) ->
console.error "ERROR: #{e}"
onfinishparser = ->
console.log "PARSER TEST DONE\n"
onfinishstream = ->
console.log "STREAM TEST DONE\n"
wantednodes =
PERSON: (person) ->
str = JSON.stringify {
name: person.children.tags.NAME[0].children.text.join()
age: person.attributes.age
}
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()