Free XML Formatting tool [closed]
Asked Answered
B

12

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.

Bedpost answered 11/10, 2008 at 5:56 Comment(10)
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.Ammonic
I found this very constructiveCirrocumulus
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.Levina
I also agree. The answers to this question provide useful information. Also, closing a question 2 years after it was asked seems rather silly.Wacky
The Best Formatter --> freeformatter.com/xml-formatter.htmlConnieconniption
Sublime Text + Indent XMLGyronny
This one is very handy to use: webtoolkitonline.com/xml-formatter.htmlNinny
I like this one, 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).Lowspirited
Another one, more like traditional editor: sourceforge.net/projects/xmltreeeditorLowspirited
1. CodVerter XML Validator - codverter.com/src/xmlvalidator 2. CodVerter XML to Plain Text - codverter.com/src/xmltotext CodVerter 3. XML to JSON - codverter.com/src/xmltojsonMarlie
B
352

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 
Bobbiebobbin answered 11/10, 2008 at 6:30 Comment(16)
You might need twu.ca/divisions/technology/sst/orion/blog/…Hartmunn
I verified this works without plug-ins. Just download the latest version of Notepad++ and it will support this.Recusant
+1 Was looking for this the other day in Notepad++Mandate
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.Phony
It's funny (misleading?) that HTMLTidy is described as a feature of Notepad++. It is a standalone tool (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.Arlyne
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 XMLBurse
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.]Avenue
I prefer Notepad++ because I can optionally copy the highlighting into emails using Plugins -> NppExport -> Copy all formats to clipboardEleventh
I think this tip about the wrapping should be in the answer itself. Will attempt to edit the answer to add it.Musketry
@Bobbiebobbin Is there any way to say not to escape xml? Because by default it is escaping it.Litterbug
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.Indiscrimination
Very nice, MUCH faster than Eclipse.Mousy
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.Acetylcholine
@Acetylcholine But that's what you need when you select '...with line breaks', right? CRLFs and Tabs. That changes the file, but not the 'document'.Avidin
I installed Notepad++ v7.5.8 (64-bit) and installed any XML plugin I could find. Nothing worked.Giffin
@Giffin 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.Reify
A
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.

Arlyne answered 11/10, 2008 at 6:49 Comment(9)
Ha, expensive "espionage"...one for the day :)Bedpost
That's a neat tool. Tiny as well.Overage
It even renders entities, that's really handy!Chole
Thanks, incredibly fast! Loaded up a ~15MB file in a few seconds!Nyasaland
this is so much better than that xml tool plugin in notepad++Chapfallen
I have a 15MB file - Notepad++ was thrashing 1 core for many minutes without a result, Visual Studio was doing the same (and slowing chewing more and more memory. Foxe can open and format it instantly - impressive. UI is plan-jane but it does the job.Indefeasible
@MikeHoney: same for me. I love Notepad++ but it was crashing on big files. I have a 45MB file, threw it at Foxe, result: instantly opened! 8|Hemisphere
Yes I've since used it on files over 300MB with no dramas.Indefeasible
I was trying to indent a 85MB xml file. This worked almost instantly. Amazing.Taxidermy
C
55

Use the following:

xmllint --format

Containment answered 11/10, 2008 at 6:18 Comment(1)
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 scriptTracheo
C
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. :-)

Corticate answered 11/10, 2008 at 11:47 Comment(3)
I used to do this :D Well, I had a proper VS edition. I'm so glad I know of better lightweight tools now!Fieldstone
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.Blameless
And can even be simplified a little since Ctrl+K, Ctrl+D formats the whole document so you can skip the Ctrl+A.Cunning
S
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.

Scrimshaw answered 18/1, 2011 at 4:40 Comment(2)
you might need to add the plugin before you can do this. add via the Plugin ManagerDermatoid
even with this plugin, NPP gets quite slower even opening 20+ MB files on my Core-i5/8GB pcPapageno
C
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

Clip answered 17/7, 2011 at 18:18 Comment(0)
V
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.

Vaud answered 13/10, 2008 at 18:23 Comment(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 repoDenman
C
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']

Court answered 7/9, 2011 at 15:45 Comment(1)
I just blogged about this here: blogs.msdn.com/b/brunoterkaly/archive/2013/01/09/…Estovers
C
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.

Consistence answered 13/10, 2008 at 18:30 Comment(1)
A notorious example of semantically significant whitespace occurs in WPF. Specifically, adjacent <Run /> tags will introduce a (usually unwanted) space in the output, unless those tags are strictly abutting in the XAML source file.Ovenware
M
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.

Mathes answered 19/10, 2008 at 16:54 Comment(0)
R
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 :/.

Resent answered 24/1, 2011 at 17:41 Comment(0)
J
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.

Jest answered 6/2, 2011 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.