Using nxml-mode
, first customize nxml-sexp-element-mode
to t
. Then normal Emacs commands like forward-sexp
, backward-sexp
, and kill-sexp
will work on elements, not just start or end tags.
Starting with "|<div class='foo'> This is some text. </div>"
(where the | illustrates the cursor position), doing C-M-d C-M-k C-M-u C-M-k <p C-c C-i C-y M-y
will replace the div with a paragraph. That's quite easy to record as a keyboard macro, although of course it'll only ever replace the tag after point with a paragraph; if you want more flexibility you'll have to write a function that prompts for the new tag to insert first.
html-mode
ornxml-mode
will have structures editing commands for this. I'm not at my computer or I'd look them up.regexp-replace
to scan and replace the html tags. I want to know what I should use to parse and modify XML in emacs.