Skip to main content

Formatting XML in Kate - KDE Editor

TLDR; 

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.

Incase, you don't have xmllint installed, simply hit
sudo apt-get install libxml2-utils
and that will install it for you.

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
and then reload our file in Kate.

  • Select text ( Complete or Partial )
  • Hit 'Ctrl + \'  or go to Tools -> Filter Text
    • Incase your Kate does not have the option for 'Filter Text' under tools, you just need to enable the 'Text Filter' plugin.
    • Go to Settings -> Plugin -> Enable 'Text Filter' and you are done.
  • Type 'xmllint --format -' and TADA! we have a formatted XML
  • Incase, you don't wish to modify the existing text, make sure you select 'Copy the result instead of pasting it'

  • Another good thing is that Kate caches the xmllint command in the text filter so you don't have to type it in again and again. 


Tested with ,

Kate: 3.8.5 / 17.04.3
Qt: 4.8.1 / 5.9.1
KDE Development Platform: 4.8.5 (4.8.5) / 5.3.8

on Ubuntu 12.04 LTS / Ubuntu 17.10

Comments

  1. Happily, this still works on 16.04 (actually KDE neon 5.12) provided you first go into settings > plugins and enable text filter. Thanks!

    ReplyDelete
  2. Very helpful. I use kate for everything and now also for XML editing. And it even works perfectly with quite large files (more then 41000 lines after format). Thanks you!

    ReplyDelete
  3. https://groomingwaves.com/the-fine-art-of-being-subtle-small-text-generator-at-your-fingertips/

    ReplyDelete

Post a Comment