Skip to content

Instantly share code, notes, and snippets.

@jmercouris
Created March 26, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmercouris/38e353766514be81a00c2dc1451f206a to your computer and use it in GitHub Desktop.
Save jmercouris/38e353766514be81a00c2dc1451f206a to your computer and use it in GitHub Desktop.
(defun encode-xml-rpc-value (arg stream)
(princ "<value>" stream)
(cond ((or (stringp arg) (symbolp arg))
(princ "<string>" stream)
(print-string-xml (string arg) stream)
(princ "</string>" stream))
((integerp arg) (format stream "<int>~d</int>" arg))
((floatp arg) (format stream "<double>~f</double>" arg))
((or (null arg) (eq arg t))
(princ "<boolean>" stream)
(princ (if arg 1 0) stream)
(princ "</boolean>" stream))
((and (arrayp arg)
(= (array-rank arg) 1)
(subtypep (array-element-type arg)
'(unsigned-byte 8)))
(princ "<base64>" stream)
(encode-base64-bytes arg stream)
(princ "</base64>" stream))
((xml-rpc-time-p arg)
(princ "<dateTime.iso8601>" stream)
(universal-time->iso8601 (xml-rpc-time-universal-time arg) stream)
(princ "</dateTime.iso8601>" stream))
((xml-literal-p arg)
(princ (xml-literal-content arg) stream))
((or (listp arg) (vectorp arg)) (encode-xml-rpc-array arg stream))
((xml-rpc-struct-p arg) (encode-xml-rpc-struct arg stream))
;; add generic method call
(t (error "cannot encode ~s" arg)))
(princ "</value>" stream))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment