views:

11301

answers:

10

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

A: 

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
@Jon - off topic but I enjoyed your talk on DotNetRocks and I live your book.
David Robbins
+2  A: 

xmllint --format

zoul
+39  A: 

I believe that Notepad++ has this feature.

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

Guy
You might need http://www.twu.ca/divisions/technology/sst/orion/blog/tidy-notepad-and-xml.html
svrist
I verified this works without plug-ins. Just download the latest version of Notepad++ and it will support this.
Michael La Voie
+1 Was looking for this the other day in Notepad++
Gordon
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.
L. Moser
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
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: yesindent:yeswrap:0This should give non-wrapped XML
Dan
+3  A: 

If you're using Windows take a look at Xml Notepad:

http://msdn.microsoft.com/en-us/library/aa905339.aspx

Download from:

http://www.microsoft.com/downloads/details.aspx?familyid=72d6aa49-787d-4118-ba5f-4f30fe913628&displaylang=en

Kev
Does XML Notepad allow you to paste an XML string and have it formatted (indented)?
Saif Khan
@Saif - yes it does, just paste into the panel next to the treeview.
Kev
@Saif - I'd go with the FirstObject editor. Way nicer.
Kev
+13  A: 

FirstObject XML editor is a great little free XML editor 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).

Ash
Ha, expensive "espionage"...one for the day :)
Saif Khan
This is EXACTLY what I was looking for.
Saif Khan
That's a neat tool. Tiny as well.
Kev
It even renders entities, that's really handy!
James B
Thanks, incredibly fast! Loaded up a ~15MB file in a few seconds!
Adam Neal
+6  A: 

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

Franci Penov
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
+2  A: 

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.

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
Miau
A: 

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.

Mihai Limbășan
+1  A: 

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  A: 

http://xmlindent.com/

delux247