Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

one line big XML to multiline

598 views
Skip to first unread message

Mihamina Rakotomandimby

unread,
Jul 2, 2012, 7:16:33 AM7/2/12
to help-gn...@gnu.org
Hi all,

I got a big one line XML file.
I want to break the lines to make it more readable.

Replacing "><" with "C-j" then indenting is the most obvious solution,
but would you know a more elegant solution?

I'm using Emacs 23 (FC17) with nXml or sgml-mode usable.

Thank you.

--
RMA.


Tassilo Horn

unread,
Jul 2, 2012, 7:51:04 AM7/2/12
to help-gn...@gnu.org
Mihamina Rakotomandimby <miha...@rktmb.org> writes:

Hi,

> I got a big one line XML file.
> I want to break the lines to make it more readable.
>
> Replacing "><" with "C-j" then indenting is the most obvious solution,
> but would you know a more elegant solution?

I'd go with some external tool such as xmllint which comes with libxml.

$ xmllint --format --output formatted.xml original.xml

should do what you want.

Bye,
Tassilo


John Bokma

unread,
Jul 2, 2012, 11:13:57 AM7/2/12
to

Xah Lee

unread,
Jul 3, 2012, 7:06:31 PM7/3/12
to
you can record a keyboard macro, save it, assign it a key. So, just
press one key, and the file is indented and well-formatted.

〈Emacs: Using Keyboard Macro to Record/Playback Keystrokes〉
http://ergoemacs.org/emacs/emacs_macro_example.html

to indent, just select all then 【Ctrl+Alt+\】.

or, this can be easily done by writing a elisp command.

Xah

Matt McClure

unread,
Jul 5, 2012, 6:46:45 PM7/5/12
to Tassilo Horn, help-gn...@gnu.org
On Mon, Jul 2, 2012 at 7:51 AM, Tassilo Horn <tas...@member.fsf.org> wrote:
> I'd go with some external tool such as xmllint which comes with libxml.
>
> $ xmllint --format --output formatted.xml original.xml
>
> should do what you want.

I prefer `xmlstarlet`[1]. To format a buffer:

C-x h C-u M-| xml fo RET

[1]: http://xmlstar.sourceforge.net/docs.php

--
Matt McClure
http://www.matthewlmcclure.com
http://www.mapmyfitness.com/profile/matthewlmcclure

0 new messages