This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to format XML in Kate?

Tags: None
(comma "," separated)
User avatar
pavel
Registered Member
Posts
134
Karma
1
OS

How to format XML in Kate?

Tue Sep 01, 2009 5:12 am
I have god non-formatted XML file (all in one string). I want to format it easily and fast.

As my text editor, I prefer Kate). It has nice XML highlighting, but no XML formatting.
airdrik
Registered Member
Posts
1854
Karma
5
OS

Re: How to format XML in Kate?

Tue Sep 01, 2009 3:33 pm
I would love to see more plugins/scripts for kate for various text-manipulation tasks like this. There may be a way to write a script for kate to do it, but I'm not sure where to get started.


airdrik, proud to be a member of KDE forums since 2008-Dec.
User avatar
Jucato
Registered Member
Posts
67
Karma
1
OS

Re: How to format XML in Kate?

Wed Sep 02, 2009 1:43 am
You can always make use of existing scripts and call them through Tools -> External Tools -> Run script.


Jucato, proud to be a member of KDE forums since 2008-Oct.
airdrik
Registered Member
Posts
1854
Karma
5
OS

Re: How to format XML in Kate?

Wed Sep 02, 2009 3:08 am
Does anyone know if there is a collection of (KDE4.x compatible) scripts and/or plugins for Kate? It looks like the only ones available are the ones that come with KDE and the kate-plugins package for KDE 3.5.

Kate seems like it should be such a nice text editor, but when you look at the available extensions it seems a little limited.


airdrik, proud to be a member of KDE forums since 2008-Dec.
User avatar
Jucato
Registered Member
Posts
67
Karma
1
OS

Re: How to format XML in Kate?

Wed Sep 02, 2009 3:37 am
You can try kde-files.org and kde-apps.org. But when I mentioned scripts up there, I really meant command line scripts, which are easier to make than Kate plugins and are more abundant. I'm sure someone somewhere has come up with a solution to a similar problem. You can run those using External Tools (or even make your own using Javascript). Google for "Kate External Tools". Here are some links I've found:

http://docs.kde.org/stable/en/kdesdk/ka ... pting.html
http://kate-editor.org/article/dcop_scr ... pplication
http://www.tuxmachines.org/node/13762


Jucato, proud to be a member of KDE forums since 2008-Oct.
airdrik
Registered Member
Posts
1854
Karma
5
OS

Re: How to format XML in Kate?

Fri Sep 04, 2009 5:25 pm
Thanks. I'll take a look.


airdrik, proud to be a member of KDE forums since 2008-Dec.
mrmenke
Registered Member
Posts
1
Karma
0

Re: How to format XML in Kate?

Thu Jan 19, 2012 12:47 pm
I had the same question stumbling over this thread. It's somewhat old, but here is my solution:

1. Make sure xmlstarlet is installed on your system
2. activate the text filter plugin in kate
3. Select all the text
3. Go to Tools->Filter Text..., enter "xmlstarlet fo" and OK.

This will format the xml file. On some systems the xmlstarlet command ist just "xml".
AlfredGebert
Registered Member
Posts
1
Karma
0

Re: How to format XML in Kate?

Wed Feb 01, 2012 11:48 am
mrmenke, thank you for the tip.
User avatar
qubodup
Registered Member
Posts
142
Karma
0

Re: How to format XML in Kate?

Fri Jun 14, 2013 12:43 pm
Thanks mrmenke.

Does anybody have suggestions for how to handle XML code that causes errors (because you want it formatted to start debugging it and you can't change how it gets generated)?

Is there any xml formatting script that ignores errors?
User avatar
abika
Registered Member
Posts
25
Karma
1
OS

Re: How to format XML in Kate?

Fri Mar 17, 2017 3:38 pm
[Bumping old thread, for incoming googlers]

A (more available) alternative to xmlstarlet is xmllint:
"Tools->Filter Text" with
Code: Select all
xmllint --format - | sed 1d

(sed removed the first "<?xml version="1.0"?>" line)

It also has the "--nowarning" option but there there seems to be no way to ignore arbitrary errors.
ahmedallbert
Registered Member
Posts
2
Karma
0

Re: How to format XML in Kate?

Mon Aug 28, 2017 10:35 am
pavel wrote:I have god non-formatted XML file (all in one string). I want to format it easily and fast.

As my text editor, I prefer Kate). It has nice XML highlighting, but no XML formatting.

Kate is one awesome editor ( If you don't like Vim for its 'CLI'ness )

When working from the command line we can use a handy tool 'xmllint' to format XML files using its --format option.

But it is a tedious task to use it when you have some content in Kate ( more so if it is an unsaved file ) and want to format it.

If you use xmllint you would do something like this,

Save File ( MySavedFile.xml )
Go to Command Line
cat MySavedFile.txt | xmllint --format - > MySavedFile.txt


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]