user1644815
user1644815

Reputation: 19

LISP downloading & parsing XML

I'm currently learning LISP and I have a quick question. Using CXML I can parse a local file easily enough, but I'm attempting to pull an XML file from the net and parse it in memory. I know there's something wrong with my code but I can't quite figure it out.

(cxml:parse-file (map 'string #'code-char
                   (drakma:http-request "http://api.eve-online.com/server/ServerStatus.xml.aspx"))
   (cxml-dom:make-dom-builder))

Upvotes: 1

Views: 696

Answers (1)

momo
momo

Reputation: 1045

(cxml:parse (map 'string #'code-char (drakma:http-request "http://api.eve-online.com/server/ServerStatus.xml.aspx")) 
                                     (cxml-dom:make-dom-builder))

result:

#<RUNE-DOM::DOCUMENT {1005BECB53}>

cxml:parse is the command you're looking for if I understand correctly based on your example. cxml:pars-stream requires a stream, and cxml:parse-file requires a file... you're giving them neither, the argument you're passing to both of them is a string.

cxml:parse-rod is more specific and will parse only strings, while cxml:parse is generic and will parse files, streams, octets, and strings.

By the way, you can also do

(cxml:parse-octets (drakma:http-request "http://api.eve-online.com/server/ServerStatus.xml.aspx") (cxml-dom:make-dom-builder))

No need to convert the binary array from drakma to a string.

Upvotes: 1

Related Questions