开发者

Formatting XML in Emacs

I have a project wit开发者_运维知识库h huge XML files that I'm copying and pasting into Emacs to edit. It's all on a single line, so I'd like to have a tool to make one XML element per line. Is there an Emacs function that I can use? I guess I'll even settle for a command-line tool that nicely integrates with Emacs, but that's not ideal.


The feature you are looking for is typically called "pretty print". There is a pretty-print function for emacs at:

http://sinewalker.wordpress.com/2008/06/26/pretty-printing-xml-with-emacs-nxml-mode/

Also, take a look at this SO question which has other options.


I wrote a little Elisp function for that, that relies on xmllint from libxml:

(defun format-xml ()
  (interactive)
  (shell-command-on-region 1 (point-max) "xmllint --format -" (current-buffer) t)
)


I've used xml-parse for years to reformat XML. The specific command you want in that package is xml-reformat-tags. Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜