How do I format XML in Notepad++?
Asked Answered
I

23

2080

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?

Isabel answered 18/10, 2010 at 16:35 Comment(3)
Configuring the XMLTools is bit tricky with latest versions. In Windows 10, Notepad++ version V6.6.8 I have configured XMLTools 2.4.7 successfully. Download the latest plugin from this link and follow the instruction in install.txt > notepad-plus-plus.org/community/topic/125/… .Rasla
Current solution for the 64bit version: superuser.com/q/1239935/333622Spitler
@Rasla seems to be resolved in latest 8.x versions of 64-bit Notepad++. Just use Plugins -> Plugins Admin and search for XMLTools and install there. The menu options to format then appear in Plugins -> XML Tools.Ative
S
2889

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

You may need to install XML Tools using your plugin manager in order to get this option in your menu.

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

Sethrida answered 18/10, 2010 at 16:48 Comment(25)
if you cant find XML Tools under Plugins, intall it from Plugins > Plugins Manager > Show Plugins ManagerCrosstree
If you get the "Errors detected in content" error when trying to use this plugin, try XML Tools -> Check XML syntax now. I had an issue where the encoding was specified as UTF-16 but was actually UTF-8. Changing the encoding attribute in the XML file fixed the problem.Chemisorption
If you use Windows 8 and an old Notepad++ installing Plugins might not work. Get the latest Notepad++ to solve this problem. 6.1.7 worked for me.Mccue
And if your Plugins Manager can't find XML Tools because you are behind a proxy at work, download it from here sourceforge.net/projects/npp-plugins/files/XML%20Tools Then copy XMLTools.dll to the plugins directory and the rest of the four dlls to the root Notepad++ directory.Kp
And if your Plugins Manager can't find XML Tools because you are behind a proxy at work This is not necessarily a problem if you've got a run-of-the-mill proxy, click Settings and enter in its details.Debase
Ad if you cannot see any plugin available, go to "updates" and update your plugin manager.Douse
@Sethrida Is there any way to enable this plugin permanently as every time I open a new XML document I need to re-enable it?Kreplach
Plugins > Plugin Manager > Show plugin manager > Available tab > Get it > Install.Teens
If your Plugins Manager can't find XML Tools because you are behind a proxy (for example at work), hit Settings in the Plugin Manager and add the proxy.Ostracism
It doesn't support proxies that require authentication. It would probably be more helpful if it used the IE/"System" settings as Chromium does.Actuary
Plugin Manager -> Settings lets you enter proxy informationPostilion
If the pretty-printing doesn't appear to change what you thought it should, then use the Plugins / XML Tools / Linarize first (puts it all on a single line with no excess white space), then pretty-print it.Boettcher
May sound stupid, but please don't forget to set the file writeable, or it will silently ignore your commands from Xml Tools. It is because those commands actually 'modify the contents' rather than switching view.Irrelevancy
Currently this plugin is called XML Tools.Efren
Won't install the plugin for me. Keep gettting a "gpup process has stopped working"Containment
And if you can't install the plugin (because of reasons like mine, our company doesn't allow plugins) - use eclipse! 1. Create a new file, tmp.xml, 2. Paste all the xmls (It can be multiple xmls also) 3. Press Ctrl+Shift+F 4. Be surprised and be happy Andrea
...AND if you don't have a Plugin Manager plugin, you can get it from here: github.com/bruderstein/nppPluginManager/releasesCanescent
My plugin manager was corrupted and wasn't allowing even the manual copy, so I reinstalled the Plugin Manager as directed at bruderste.in/npp/pm/#install.Baskerville
If anyone in 2019 or later comes across this question, this answer over on superuser.se worked for me (npp 7.6.6 32-bit): superuser.com/a/1421246/41699Ferneferneau
I didn't find settings button in Plugin Admin in v7.6 (Yes, they also changed the menu name) where you can edit the proxy. Reading https://mcmap.net/q/45742/-configure-proxy-settings-in-notepad-via-plugin-manager will help by running updater\GUP.exe -options.Defoliate
Doesn't seem to have a way to specify the indent, but if you change the first indentation in the file it will use that convention for the rest of the document.Quidnunc
the github link of the plugin github.com/morbac/xmltools/releasesClaude
in Notepad++ v7.8.9, to add proxy: run as administrator, then menu ? > Set Updater ProxyEmbolden
Notepad++ v7.9 includes a plugin manager and updater.Lamdin
It's still available, but if you cant find XML Tools under Plugins it is now installed from Plugins > Plugins Admin and then just search "XML" in the search box ... a couple quick clicks later you'll be installing ... thanks @Crosstree for setting me on the right path!Cindelyn
V
161

You need to install the XML tool from the Plugins menu item → Plugins Admin...Plugins Admin dialog appears and then scroll to bottom of available plugins and check the XML tools, install it and then Ctrl + Alt + Shift + B OR the option for XML Tool above shows up.

Vignette answered 25/6, 2012 at 21:0 Comment(0)
M
134
Step 1: Install XML Tools plugin
Step 2: Format ....completed

enter image description here

Moneymaker answered 24/12, 2015 at 10:32 Comment(2)
great answer, however i don't have the "Plugin Manager" o_O Can someone help? Was it removed meanwhile?Gambia
worked for me..For the new versions of notepad++ have plugin admin instead of plugin managerSupremacy
G
45

Try TextFX → TextFX Html Tidy → Tidy: reindent XML

If you can't try with Eclipse, do right button, source, and correct indent.

Gaunt answered 18/10, 2010 at 16:45 Comment(7)
Thanks for the answer but I am not able to find Tidy: reindent XML in my TextFX Html Tidy menu. Can you tell me what I am missing?Isabel
If you have no global "TextFX" option then you need to install the plugin named TextFX. But that's not enough, apparently 6.x versions are also missing the libtidy.dll download so you have to go through hoops to get it. Then you will have a Tidy: reindent XML option (I presume)Fideliafidelio
I have such option but it does nothing (and gives no error message).Shutin
For anyone else wondering, the hoops mentioned by @Fideliafidelio are discussed hereDiorio
@DanubianSailor Same issue for me. I've had to play with XML Tools and found one of the formatting options there worked.Ative
The main issue I have with TidyXML is that it's maddeningly slow for any file over a meg or two.Lineage
TextFX has been phased out - from TextFX's Future: "... bid farewell to an aging workhorse that has served the community well."Oswell
P
44

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.

Parthenogenesis answered 15/11, 2013 at 13:39 Comment(0)
C
22

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

Councilwoman answered 5/9, 2014 at 4:27 Comment(4)
When I use UniversalIndentGUI to indent one big line of XML, it doesn't work. I have no change.Phototherapy
I checked again and it doesn't work just after installing the plugin. You have to edit settings of the plugin, go to XML Indent options and check the Force newline option. Now it works. Thanks for the tips because it helps for XML not 100% correct :)Phototherapy
UniversalIndentGUI worked for me where other options have failed, not sure why except that the XML file I was prettifying was 40MB plus. It was also extremely quick. Props to Alex for the XML force newline option tip.Hoicks
TextFX has been phased out - from TextFX's Future: "... bid farewell to an aging workhorse that has served the community well."Oswell
A
18

All the previous answers do not define how to add the plugin manager in your Notepad++ installation.

This is for the folks who do not see the the plugin manager in the plugin tab

Download the plugin manager from this link - this is for the 64-bit plugin manager. Once you download the plugin manager, paste in the plugin folder. This is was my location of plugin folder: C:\Program Files\Notepad++\plugins

Enter image description here

After pasting the .dll file restart Notepad++. Now you can install any plugin. To install a plugin, click on the plugin tab, then go to plugin manager and select the plugin whatever you want.

Adaminah answered 4/9, 2018 at 8:27 Comment(0)
I
16

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.

Isobaric answered 4/9, 2012 at 18:43 Comment(2)
I was trying to compare 2 different environment config files...that had 10 or so different settings...but the xml attributes were on one-line in one file and on different lines in the other xml file. Only by doing both of these did the actual differences pop up on a file-compare tool. Thanks.Clouded
TextFX has been phased out - from TextFX's Future: "... bid farewell to an aging workhorse that has served the community well."Oswell
B
11

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)
Booby answered 15/5, 2013 at 16:33 Comment(0)
N
11

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.

Nazarene answered 1/6, 2017 at 13:0 Comment(0)
S
11

Plugins -> Plugins Admin -> search for XML Tools

Once install the XML Tools Plugin

select the entire XML file content and click on pretty print

or

Ctrl+Alt+Shift+B

Sitdown answered 9/11, 2021 at 17:8 Comment(1)
The option is in the menu Plugins > XML Tools > Pretty print (believe it or not, I couldn't find it). It's not necessary to select the entire XMLFacelifting
S
6

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

Strudel answered 23/7, 2014 at 2:26 Comment(0)
C
6

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.

Controvert answered 3/7, 2015 at 6:1 Comment(0)
S
5

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 DreamWeaver even if it is driving me insane being slow and unresponsive from time to time...

Sorci answered 11/1, 2012 at 3:12 Comment(3)
yes, things have changed a lot in the new version, but I was still un able to solve it out!Isabel
for versions 5.9.x, go to plugins -> plugin manager -> show plugin manager and you can add it from hereKylix
The ability to add or not add certain features might be weird at first, BUT that is why so many people USE Notepad++ over much bulkier products like DreamWeaver! YOU decide how thin or fat your program is rather than have the kitchen sink load all day every day... (and, this should have been a comment rather than a submitted answer)Decalcomania
G
5

The location of XML tools has changed slightly since this question was first asked.

I am currently using Notepad++ v7.8.6

New location is:

  • Plugins tab
  • Plugins Admin...
  • Plugins Admin dialog appears with Available plugins tab as the default
  • Scroll to the bottom and check the XML Tools checkbox
  • Click Install button in top right of the dialog

This will close Notepad++ while it installs and then restart it automatically.

Then there are a couple keyboard shortcuts to beautify the XML:

  • Pretty Print: Ctrl + Shift + Alt + B
  • Pretty Print (indent attributes): Ctrl + Shift + Alt + A

To see more XML Tools options:

  • Plugins tab
  • XML Tools option
Glut answered 24/6, 2020 at 5:24 Comment(0)
G
4

"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.

Gilly answered 25/4, 2013 at 20:2 Comment(1)
XMLTools will complain if there is no root element. If your XML is otherwise valid, you can fix it by just adding something like <root>/</root> at the top/bottom.Rotor
I
4

The latest version of Notepad++ x64 v7.6.2 on Windows 10 already moved the plugin manager to 'Plugins Admin'.

Old versions of Notepad++ and plugin manager won't work.

Ingra answered 23/1, 2019 at 10:28 Comment(0)
C
3

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...

Cerelia answered 20/3, 2014 at 17:46 Comment(1)
TextFX has been phased out - from TextFX's Future: "... bid farewell to an aging workhorse that has served the community well."Oswell
J
3

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 content in the input window
  2. Click the "Beautify / Format" button
  3. Copy formatted XML output from the result window
  4. Paste in Notepad++

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

Jessamyn answered 6/6, 2018 at 17:43 Comment(2)
Only do this if your xml does not contain any sensitive/private dataMonteverdi
codebeautify stores the xml we paste there so it is better to avoid such tools.Emery
S
3

You can't, granted you don't have access to install plugins. But you probably have or can get Eclipse (Visual Studio can do this too).

Ctrl + N (new file) → (choose XML file) → (paste your XML content) → Ctrl + Shift + K (format)

If you want to format JSON NotePad++ can do this by default with Ctrl + Alt + m

Schwejda answered 20/11, 2018 at 18:56 Comment(0)
G
2

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 Windows XP. There are instructions above for manual installation of various DLL files, 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!

Gerald answered 6/5, 2015 at 14:58 Comment(0)
A
1

IT is manual way of doing formatting using regular expression ,put this expression and do replace all enter image description here

Alvey answered 24/11, 2023 at 9:15 Comment(1)
This doesn't format anything, it just add a linefeed before open tag.Safekeeping
U
0

With some xml text in a tab, just click on the Language menu and choose XML.

This is with Notepad++ version 8.5.8. Assume older versions did not have this capability? Much simpler now.

There are no special plugins that I had to install.

Unseemly answered 27/10, 2023 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.