How to format XML in Notepad++?

happyhardik Source

I have Notepad++ and I got some XML code which is very long. When I pasted it in Notepad++ there was a long line of code (difficult to read and work with).

I want to know if there is a simple way to make the text readable (by readable I mean properly tabbed code).

I can do it manually but I want a permanent solution to this as I have faced this several times. I am sure there is a way to do this as I have done it once before a couple of years back, maybe with Visual Studio or some other editor, I don't remember.

But can Notepad++ do it?

notepad++code-formatting

Answers

answered 8 years ago Torres #1

Try TextFX --> TextFX Html Tidy --> Tidy: reindent XML

If you can´t try with Eclipse, right button, source, correct indent

answered 8 years ago erjiang #2

Try Plugins -> XML Tools -> Pretty Print (libXML) or (XML only - with line breaks Ctrl + Alt + Shift + B)

In my experience, libXML gives nice output but only if the file is 100% correctly formed.

answered 7 years ago Snowalker #3

There is no such a thing like TextFX in Notepad++, not in the latest version at least. This is one of the reasons I'm still with DW even if it is driving me insane being slow and unresponsive from time to time...

answered 6 years ago abhi #4

You need to install the XML tool from the Plugins --> Plugin Manager --> show Plugin Manager and then check the XML tools, install it and then Ctl+Alt+Shift+B OR the option for XML Tool above shows up.

answered 6 years ago Some Noob Student #5

For best results, you should use both TextFX XML tidy and XML tools pretty print. Here's how and why:

1.TextFX -> TextFX HTML Tidy -> Tidy: reindent XML

TextFX has the benefit of wrapping long lines, which XML Tools does not do, but it doesn't indent those new lines correctly.

2. XML Tools -> Pretty print (Text indent)

XML Tools complements TextFX by indenting the newly wrapped lines nicely.

answered 5 years ago phish_bulb #6

"But can Notepad++ do it?"

If the XML is invalid, the answer is apparently 'no'. I tried Notepad++ with the Tidy2 and XMLTools plugins. Both give errors similar to "errors encountered, please fix". If you don't care about errors, that's a PITA.

Instead, open it in visual studio then edit -> advanced -> format document. Quick and pretty.

answered 5 years ago Michael B #7

OK, here is how I did it in Notepad++:

  • Plugins
  • Plugin manager
  • Show plugin manager
  • Check XML tools
  • Install
  • Restart Notepad++
  • Open XML file
  • Plugins
  • XML tools
  • Pretty print (XML only -- with line breaks)

answered 5 years ago jbigman #8

Plugins -> XML Tools -> Pretty Print (libXML) or Ctrl+Alt+Shift+B

You probably need to install the plugin:

Plugins > Plugins Manager > Show Plugins Manager

If you are behind a proxy, download it from here.

Then copy XMLTools.dll to the plugins directory and external libraries (four dlls) into the root Notepad++ directory.

answered 4 years ago Banzai #9

If your XML is imperfect, try this with the TextFX Characters plugin (install from Plugin manager):

First, find a ">" to copy into the clipboard. Then select ALL your text, and then...

On the main menu: TextFX -> TextFX Edit -> Solit lines at clipboard char...

This will do a reasonable job, not perfect, but things will be readable, at least.

I had to do this with XML code stored in an SQL Server database, where the headers weren't stored, just the XML body...

answered 4 years ago hoggar #10

Notepad++ v6.6.3 with plugin "XML Tools" and shortcut Ctrl + Alt + Shift + B works fine.

answered 4 years ago Sameera R. #11

Here are most of plugins you can use in Notepad++ to format your XML code.

  • UniversalIndentGUI
    (I recommend this one)

Enable 'text auto update' in plugin manager-> UniversalIndentGUI
Shortkey = CTRL+ALT+SHIFT+J

  • TextFX
    (this is the tool that most of the users use)

Shortkey = CTRL+ALT+SHIFT+B

  • XML Tools
    (customized plugin for XML)

Shortkey = CTRL+ALT+SHIFT+B

answered 3 years ago user3070485 #12

UniversalIndentGUI did the job for me, once configured properly as described above.

TextFX would not install and run correctly on an old PC I have running XP. There are instructions above for manual installation of various DLLs but I'd rather avoid any manual installation.

UniversalIndentGUI formatted some lines like this

        <ClockStatus>1
        </ClockStatus>

and I would have preferred

        <ClockStatus>1</ClockStatus>

but the output is still much better than one long line!

answered 3 years ago thanga #13

You can find details here To Quickly Format XML using Pretty Print (libXML)

Installing the XML Tools

If you run Notepad++ and look in the Plugins menu, you’ll see that the XML Tools aren’t there:

  1. Download the XML tools from here.

  2. Unzip the file and copy the XMLTools.dll to the Notepad++ plugins folder (in the example above: C:\Program Files (x86)\Notepad++\plugins):

  3. Re-start Notepad++ and you should now see the XMLTools appear in the Plugins menu.

  4. Unzip the ext_libs.zip file and then copy the unzipped DLLs to the Notepad++ installation directory (in the example above: C:\Program Files (x86)\Notepad++).

  5. Re-start Notepad++ and you should finally see the proper XML Tools menu.

  6. The feature I use the most is “Pretty print (XML only – with line breaks)”. This will format any piece of XML with all the proper line spacing.

answered 3 years ago iCrazybest #14

Step 1: Install XML Tools plugin
Step 2: Format ....completed

enter image description here

answered 1 year ago ᗩИᎠЯƎᗩ #15

If you get this error:

Notepad++ Error: Cannot load 32-bit plugin

Cannot load 32-bit plugin, XMLTools.dll is not compatible with the current version of Notepad++

Here you can find a working version for Windows 10 x64: Xml Tools 2.4.9.2 Unicode

Note: It's the only version I've found working on Windows 10 Professional x64.

answered 1 month ago rsmith #16

Since I see lots of comments about people having problems with the plugin, I thought I'd mention the work around that I use.

I just use one of the online sites for xml viewing (I use https://codebeautify.org/xmlviewer but there are plenty out there) as follows: (1) paste the xml in input window (2) click "Beautify / Format" button (3) copy formatted xml output from result window (4) paste in notepad++

I don't know if it qualifies as answering the OP question exactly but its very simple and easy for anyone who is having problems with the plugin.

comments powered by Disqus