fs = require 'fs'
http = require 'http'
crypto = require 'crypto'
-expat = require 'node-expat'
+xml = require 'node-xml'
auth = {}
res.on 'data', (chunk) ->
body += chunk
res.on 'end', ->
- parser = new expat.Parser 'UTF-8'
cur_tag = ''
done = false
- parser.on 'startElement', (name, attrs) ->
- cur_tag = name
- parser.on 'text', (str) ->
- if cur_tag is 'key'
- done = true
- auth.sk = str
- console.log("got key \"#{str}\"")
- callback null, str
- else if cur_tag is 'error'
- done = true
- callback "login failed: #{str}"
- # ignore other stuff in there
+ parser = new xml.SaxParser (cb) ->
+ cb.onStartElementNS (name, attrs, prefix, uri, namespaces) ->
+ cur_tag = name
+ cb.onCharacters (str) ->
+ if cur_tag is 'key'
+ done = true
+ auth.sk = str
+ console.log("got key \"#{str}\"")
+ callback null, str
+ else if cur_tag is 'error'
+ done = true
+ callback "login failed: #{str}"
+ # ignore other stuff in there
unless parser.parse body, true
done = true
callback "login server response wouldn't parse as XML."