2012-11-12 43 views
0

我正在使用url-retrieve-synchronously函數,它返回一個包含響應的緩衝區。我想知道是否有一個非hacky的方式來獲得響應的主體,並能夠將它傳遞給xml-parse-region。如何從emacs中的url解析xml?

是否存在一個xml-parse-from-url函數?我如何解析url-retrieve的響應?

回答

0

在identica-mode.el(在GNU GPL 2版本授權),還有將要使用的URL,檢索並把它傳遞給XML解析器的功能,並返回解析響應:

(defun identica-get-response-body (&optional buffer) 
    "Extract HTTP response body from HTTP response, parse it as XML, and return a XML tree as list. 
`buffer' may be a buffer or the name of an existing buffer. 
If `buffer' is omitted, current-buffer is parsed. 

Removed the call to `identica-clean-response-body'." 
    (or buffer 
     (setq buffer (current-buffer))) 
    (set-buffer buffer) 
    (set-buffer-multibyte t) 
    (let ((start (save-excursion 
     (goto-char (point-min)) 
     (and (re-search-forward "<\?xml" (point-max) t) 
       (match-beginning 0))))) 
    ;;(identica-clean-response-body) ; necessary for identica, cleaned up some weird characters 
    (and start 
     (xml-parse-region start (point-max))))) 
0

您可以看看Emacs發佈的一些軟件包如何實現它。例如,lisp/net/newst-backend.ellisp/net/soap-client.el

+0

你能粘貼一些代碼?我似乎無法發現,在我自己的emacs本地安裝,我甚至試圖'find-grep'使用'url-retrieve' –