Kev's Development Toolbox
Development Utils: Back
XML Formatted Viewer
Overview

Formats xml source that is pasted into the main display area.

Jar File XMLFormattedViewer.zip
Source jar XMLFormattedViewer_src.jar
Javadoc api XMLFormattedViewer_docs.jar


Description

I developed this application for debugging xml data being sent between systems. Sometimes when xml is output to the console for debugging purposes it is not in the easiest format to read - this app reformats the xml to be in a hierachical tree and displays it in both an editable text area and a graphical tree.

It will take xml formatted in any way, for example:

Input XML Formatted Result
<?xml version="
1.0"?><test xml
ns:test="http:/
/www.testns.com
/test" testatt=
"this is the ro
ot node"><elem
ent1 testatt1=
"testvalue1"><
/element1><ele
ment2 testattr
="test value">
<test:child1>d
ata</test:chil
d1><test:child
2/></element2>
</test>
<test xmlns:test="http://www.testns.com/test" testatt="this is the root node">
	<element1 testatt1="testvalue1"></element1>
	<element2 testattr="test value">
		<test:child1>data</test:child1>
		<test:child2></test:child2>
	</element2>
</test>


Running the app

Unzip the XMLFormattedViewer.zip to a directory on your machine.

1. On a jdk 1.4+ platform (already includes JAXP1.1 apis), from the directory where you unzipped the zip file, run from a command line:

java kh.XMLFormattedViewer

2. on a Java platform prior to 1.4: the JAXP1.1 api, Xerces1.3.1 and Xalan J2.3.1 are included in the lib directory. The supplied run_xerces.bat and setenv.bat (called by run_xerces.bat) file will run the app on a Windows platform (for other platforms you will have to edit these files to set your classpath accordingly).

run_xerces.bat

Please read the readme.txt file in the zip file for more information.

Editing the XML source directly

The app will format the xml as soon as it is pasted into the text area. To edit the xml directly (or to type the xml source directly into the window rather than pasting it in), uncheck the 'Validate XML' check box in the bottom left to turn off the validate (unchecked = no validation). When you want to validate and formatted the xml, check the box to turn back on.

Handling Spaces and empty text elements

If your source element contains a lot of empty text elements, and or spurious tab characters or spaces, the app can strip these out to give a cleaner format - press the 'Strip Spaces' button to do this.

Screenshots

1. Main application window

2. Main window showing unformatted xml source pasted in:

3. Fomatted text view:

4. Formatted text and tree view:

Site designed and
developed by
MindBeans Software Consulting: Independent Consultants - Software Design and Development
© Copyright Kevin Hooke, MindBeans Software Consulting 2002-2008.
All Rights Reserved.
Running on JBoss4.2.0/Tomcat5.0, Linux Fedora Core FC4 2.6.11
Current uptime last checked at: Fri May 23 22:08:39 PDT 2008
22:08:39 up 19 min, 2 users, load average: 0.02, 0.22, 0.28
  Last updated: Oct 2007 v2.0