开发者

Formatting XML in Emacs

开发者 https://www.devze.com 2022-12-18 13:50 出处:网络
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

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

精彩评论

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

关注公众号