226

Is there a free XML formatting (indent) tool available where I can past an XML string and have it formatted so I can read the XML document correctly?

Thanks

Edit ~ I am using XML Notepad on Windows XP.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Saif Khan
  • 18,402
  • 29
  • 102
  • 147
  • 47
    I found this very constructive – JGilmartin Feb 28 '12 at 16:04
  • 18
    Agree. This question actually is a good fit to the Q&A: there was a factual answer to a narrow question. This question shouldn't have been closed. – Ben Collins Mar 02 '12 at 23:06
  • 5
    I also agree. The answers to this question provide useful information. Also, closing a question 2 years after it was asked seems rather silly. – Bill W Jul 18 '12 at 12:39
  • The Best Formatter --> http://www.freeformatter.com/xml-formatter.html – AZ_ Jul 27 '12 at 08:20
  • 1
    What platform are you on? What text editor are you already using? Most decent text editors either support this out of the box or have add-ons available. – Jon Skeet Oct 11 '08 at 06:12
  • Sublime Text + Indent XML – Ziyuan Jun 05 '14 at 15:50
  • This one is very handy to use: http://www.webtoolkitonline.com/xml-formatter.html – Benny Code Apr 18 '16 at 13:59
  • I like this one, https://xmlexplorer.codeplex.com/, not really an editor, but rather a browser, displays tree hierarchiy, accepts XPath queries, and very low footprint (I used with files of 30 MBs). Good for getting the big picture (of the document structure). – Fernando Gonzalez Sanchez May 22 '17 at 18:30
  • Another one, more like traditional editor: https://sourceforge.net/projects/xmltreeeditor/ – Fernando Gonzalez Sanchez May 22 '17 at 18:39
  • 1. CodVerter XML Validator - https://codverter.com/src/xmlvalidator 2. CodVerter XML to Plain Text - https://codverter.com/src/xmltotext CodVerter 3. XML to JSON - https://codverter.com/src/xmltojson – Jonathan Applebaum Feb 09 '19 at 09:46

12 Answers12

351

I believe that Notepad++ has this feature.

Edit (for newer versions)
Install the "XML Tools" plugin (Menu Plugins, Plugin Manager)
Then run: Menu Plugins, Xml Tools, Pretty Print (XML only - with line breaks)

Original answer (for older versions of Notepad++)

Notepad++ menu: TextFX -> HTML Tidy -> Tidy: Reindent XML

This feature however wraps XMLs and that makes it look 'unclean'. To have no wrap,

  • open C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI,
  • find the entry [Tidy: Reindent XML] and add wrap:0 so that it looks like this:
[Tidy: Reindent XML] 
input-xml: yes 
indent:yes 
wrap:0 
pauloya
  • 2,535
  • 3
  • 30
  • 50
Guy
  • 65,082
  • 97
  • 254
  • 325
  • 3
    You might need http://www.twu.ca/divisions/technology/sst/orion/blog/tidy-notepad-and-xml.html – svrist Jan 21 '09 at 09:19
  • 3
    I verified this works without plug-ins. Just download the latest version of Notepad++ and it will support this. – Michael La Voie Jul 31 '09 at 23:46
  • 1
    +1 Was looking for this the other day in Notepad++ – Gordon Jan 25 '10 at 10:21
  • 1
    Who would have ever thought you'd get this many up votes for pointing out a feature in Notepad++? But once I used it, I up voted it too. Thanks for the tip. – LJM Jun 04 '10 at 18:46
  • 7
    It's funny (misleading?) that HTMLTidy is described as a feature of Notepad++. It is a standalone tool (http://tidy.sourceforge.net/) that has been around much longer than Notepad++ and can be used in any text editor that supports external tools. I used it for ages from the command prompt before I found FirstObject XML Editor. – Ash Jun 15 '10 at 01:04
  • 8
    Notepad++ 's XML indent feature however wraps XMLs and that makes it look 'unclean'. I like the way IE represents it. To have no wrap for "Tidy: Reindent XML", open "C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI", find the entry "[Tidy: Reindent XML]" and add "wrap:0" so that it looks like this: [Tidy: Reindent XML] input-xml: yes indent:yes wrap:0 This should give non-wrapped XML – Joseph Jul 20 '10 at 05:15
  • I prefer Notepad++ because I can optionally copy the highlighting into emails using Plugins -> NppExport -> Copy all formats to clipboard – Richard Nienaber Jan 17 '11 at 10:58
  • I think this tip about the wrapping should be in the answer itself. Will attempt to edit the answer to add it. – Nicolas C Feb 18 '11 at 09:35
  • @Guy Is there any way to say not to escape xml? Because by default it is escaping it. – angularrocks.com Apr 21 '11 at 01:12
  • 21
    Just FYI, the newest version of Notepad++ (5.9 at the time of writing) does not include TextFX, and getting it to work requires manual building of a DLL. In the Plugin Manager, install the XML Tools plugin -- MUCH easier. – Alex Beardsley Jun 10 '11 at 15:09
  • Very nice, MUCH faster than Eclipse. – Michael Jul 20 '12 at 15:42
  • One thing to be aware of, if you use Pretty Print (XML only - with line breaks) and then modify the file and save it, a CR/LF will be written to the file at the end of each line. By using Pretty Print (XML only - with line breaks) you are not just changing the view of the file, you are changing the file contents as well. Use View / Show Symbol / Show all characters to see the added control chars in the file. – Tary Feb 05 '13 at 20:43
  • Notepad++ seems to need to run as administrator (in Windows 7) to be able to Reindent XML, even at a 'random' location. It took me quite a while before I figured that one out. [I guess this is more like a comment, but I don't have enoug Rep for that.] – Yahoo Serious Nov 11 '10 at 13:23
  • @Tary But that's what you need when you select *'...with line breaks'*, right? `CRLF`s and `Tab`s. That changes the file, but not the 'document'. – Janusz Lenar Mar 18 '13 at 11:04
  • I installed Notepad++ v7.5.8 (64-bit) and installed any XML plugin I could find. Nothing worked. – Peter Oct 05 '18 at 10:13
  • @Peter you have to install the 32 bit version of notepad++. The Plugin Admin option is not available under the Plugins menu in the 64 bit version. – Rich Jan 07 '19 at 16:05
61

Firstobject's free XML editor for Windows is called foxe is a great tool.

Open or paste your XML into it and press F8 to indent (you may need to set the number of indent spaces as it may default to 0).

It looks simple, however it contains a custom written XML parser written in C++ that allows it to work efficiently with very large XML files easily (unlike some expensive "espionage" related tools I've used).

From the product page:

The full Visual C++ source code for this firstobject XML editor (including the CDataEdit gigabyte edit control MFC component) is available as part of the Advanced CMarkup Developer License. It allows developers to implement custom XML handling functions such as validation, transformation, beautify, and reporting for their own purposes.

Adriano
  • 19,463
  • 19
  • 103
  • 140
Ash
  • 60,973
  • 31
  • 151
  • 169
54

Use the following:

xmllint --format

zoul
  • 102,279
  • 44
  • 260
  • 354
  • my cygwin distro already had this so I guess I didn't need to download the windows binary and then decide I'd rather write a bash script – vinnyjames Apr 09 '13 at 20:58
22

You can open the XML file in any Visual Studio Express product and the press Ctrl+A, Ctrl+K, Ctrl+F to get it nicely formatted.

Hey, it's free and it's a tool, so it fits the question. :-)

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
Franci Penov
  • 74,861
  • 18
  • 132
  • 169
  • I used to do this :D Well, I had a proper VS edition. I'm so glad I know of better lightweight tools now! – jamiebarrow Oct 20 '10 at 09:03
  • 2
    All this time, I've been copying it from VS to Notepad++ just to format the xml, and I could have just done that! What's more, I use Ctrl+K Ctrl+F to format code already. :-) Nice one. – Lee Oades Oct 10 '11 at 13:14
  • 2
    And can even be simplified a little since Ctrl+K, Ctrl+D formats the whole document so you can skip the Ctrl+A. – Hans Olsson Feb 11 '13 at 13:49
17

Another method to reindent XML in Notepad++:

From menu select Plugins -> XML Tools -> Pretty print (XML only – with line breaks)
or press Ctrl+Alt+Shift+B.

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
Maksym Kozlenko
  • 10,273
  • 2
  • 66
  • 55
5

You could also try http://xmltoolbox.appspot.com/ it is an online xml formatter. You just paste your xml into a large text area field and press "format xml" then it pretty prints the xml in the text area so its easy to read or copy.

There is also a nice little filter feature that allows you to see all of a certain element.

Hope you will enjoy the tool

Ole Bille
  • 59
  • 1
  • 1
4

If you use Notepad++, I would suggest installing the XML Tools plugin. You can beautify any XML content (indentation and line breaks) or linarize it. Also you can (auto-)validate your file and apply XSL transformation to it.

Download the latest zip and copy the extracted DLL to the plugins directory of your Notepad++ installation. Also, download the External libs and copy them to your %SystemRoot%\system32\ directory.

  • 1
    Actually you will need the ext_libs as well, there is an exe that will do the whole thing for you in the source forge repo – roundcrisis Aug 05 '09 at 10:50
3

Advanced Conventional Formatting [Update]

XMLSpectrum is an open source syntax-highlighter. Supporting XML - but with special features for XSLT 2.0, XSD 1.1 and XPath 2.0. I'm mentioning this here because it also has special formatting capabilities for XML: it vertically aligns attributes and their contents as well as elements - to enhance XML readability.

The output HTML is suitable for reviewing in a browser or if the XML needs further editing it can be copied and pasted into an XML editor of your choice

Because xmlspectrum.xsl uses its own XML text parser, all content such as entity references and CDATA sections are preserved - as in an editor.

enter image description here

Note on usage: this is just an XSLT 2.0 stylesheet so you would need to enclose the required command-line (samples provided) in a small script so you could automatically transform the XML source.

Virtual Formatting

XMLQuire is a free XML editor that has special formatting capabilities - it formats XML properly, including multi-line attributes, attribute-values, word-wrap indentation and even XML comments.

All XML indentation is done without inserting tabs or spaces, ensuring the integrity of the XML is maintained. For versions of Windows later than XP, no installation is needed, its just a 3MB .exe file.

If you need to print out the formatted XML there are special options within the print-preview, such as line-numbering that follows the indentation. If you need to copy the formatted XML to a word processor as rich text, that's available too.

[Disclosure: I maintain both XMLQuire and XMLSpectrum as 'home projects']

pgfearo
  • 2,087
  • 1
  • 22
  • 27
  • 1
    I just blogged about this here: http://blogs.msdn.com/b/brunoterkaly/archive/2013/01/09/how-to-format-xaml-easily-and-effectively-windows-8-wpf-silverlight.aspx – Bruno Jan 15 '13 at 15:42
1

Not directly an answer, but good to know nevertheless: After indenting, please make sure that the parser(s) and application(s) which will subsequently process the formatted XML will not yield different results. White space is often significant in XML and most conforming parsers bubble it up to the application.

Yahoo Serious
  • 3,728
  • 1
  • 33
  • 37
Mihai Limbășan
  • 64,368
  • 4
  • 48
  • 59
  • A notorious example of semantically significant whitespace occurs in **WPF**. Specifically, adjacent `` tags will [introduce a (usually unwanted) space in the output](https://stackoverflow.com/questions/11090084/how-to-get-rid-of-whitespace-between-runs-in-textblock), unless those tags are strictly abutting in the **XAML** source file. – Glenn Slayden Jun 23 '18 at 22:03
1

If you are a programmer, many XML parsing programming libraries will let you parse XML, then output it - and generating pretty printed, indented output is an output option.

JohnnySoftware
  • 2,053
  • 16
  • 15
1

Notepad++ dit it well only if you're in ANSI. If you do it in something like "ANSI AS UTF8", tidy dirty the doc :/.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
ykatchou
  • 3,667
  • 1
  • 22
  • 27
1

Try http://prettydiff.com/ The algorithm is similar to HTML Tidy, but is more complete. The program is written entirely in JavaScript, so you don't have to install anything.