Eclipse XML formatter
Solution 1
This is way less than ideal, and I hope someone has a better solution, but it works:
Build a simple App using dom4j:
public static void main( final String[] args ) throws Exception {
String text = FileUtils.readFileToString( new File( args[ 0 ] ) );
OutputFormat format = OutputFormat.createPrettyPrint();
format.setTrimText( false );
XMLWriter writer = new XMLWriter( System.out, format );
writer.write( DocumentHelper.parseText( text ) );
}
Create a runnable jar, (optional) batch script, and add as an external tool. Of course, you could try XMLTidy or some other command line XML formatter, but I have had better results with dom4j.
Solution 2
You can try this one if you like
Solution 3
I like Notepad++ with the XML Tools plugin. It does XSLT, has an XPATH expression evaluator, and does DTD and schema validation. Toolchain download links:
- Notepad++: http://sourceforge.net/project/downloading.php?group_id=95717&use_mirror=internap&filename=npp.5.0.Installer.exe&24657954
- XML Plugins: http://sourceforge.net/project/downloading.php?group_id=189927&use_mirror=voxel&filename=xmltools_2.3.1_r639.zip&44936797
- External Libraries: http://sourceforge.net/project/downloading.php?group_id=189927&use_mirror=internap&filename=ext_libs.zip&52274848
Solution 4
I have used XMLBuddy in the past http://www.xmlbuddy.com/
before I reverted to OxygenXML but you have to pay for Oxygen.
Solution 5
The Eclipse XML Editor will honor CDATA
sections and won't do any formatting within those sections. I tested this with kepler. This is slightly more to type, but one can use a template from preferences -> XML -> XML Files -> Editor -> Templates
to make this easier.
javamonkey79
Hi, I'm Shaun! I enjoying creating software. I started my career in enterprise integration (think: camel, activemq, java). Nowadays, I typically work on back end data systems (databases, datastores, publishing, infrastructure). I work on the data engineering team, at edmunds.com (beep beep). In my formative years I was primarily interested java, Eclipse and maven, and I also use to dink around in Python, Perl, Bash Scripts, Windows Scripts, HTML, javascript, PHP, CSS, C, ASP, VB, C#, OSGi, PDE, RCP...and the list goes on. Since 2017, I've gone back end to front end and and back again, working on service engineering teams (tomcat, spring, java) to front end teams (react, redux, bootstrap) and finally back again to where I am now on data engineering (spark, spark-sql, databricks, scala). I use to blog here and here is my gitlab account here if you want to see some of the open source stuff I've done.
Updated on July 31, 2022Comments
-
javamonkey79 almost 2 years
What is a free alternative to the built-in Eclipse XML editor?
The one packaged with the IDE has two major problems with formatting:
- The formatter tries to parse escaped char's as though they were unescaped. E.g. '<' is treated like '<' which causes the formatter to "stop".
-
White space between elements is not honored:
<foo> text </foo>
will be formatted to:
<foo>text</foo>
We are using Eclipse 3.4.
Updates
Issue #1 is a known bug: Formatting issues with entities in XML files.
Apparently the white space formatting is intended functionality. I have requested this be provided as an option or advise on fixing this in a plugin of my own, but as of yet, no answer.
-
javamonkey79 over 15 yearsI have the 'Eclipse XML Editors and Tools 3.0.3' installed already. Have you tried creating a tag with white space in the data and then formatting? How about escape chars? If it works for you then I wonder if it is some setting...
-
javamonkey79 over 15 yearsXMLbuddy is not free so far as I can tell.
-
javamonkey79 over 15 yearsp.s. I'd happily pay for\expense a full featured plugin if that is what I needed. However, I just need simple formatting and outline presentation.
-
Admin over 13 years+1. Programming is one of the few professions where you can create the tools you then use every day, and more should take advantage of that.
-
javamonkey79 over 13 years@Roger: Amen to that. I've wrote quite a few plugins for Eclipse, Maven mojo's, scripts, tools, etc than I think I have "legitimate" projects. It's almost always fun and interesting - and pragmatic to boot :)