File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes Pretty printing XML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Pretty printing XML" Watch "Pretty printing XML" New topic
Author

Pretty printing XML

William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Has anyone seen code that will pretty print my XML? Something with less over-head than a real parser? Thanks.


Please ignore post, I have no idea what I am talking about.
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi,
One of the IBM DOM tutorial says that
System.out.println(root.toString()); will print the XML in a non-normalized way,its also say that you may not see the output pretty printed due to version conflict,you can give a try with ur java version.


Spritle Software Blogs
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Really?
And 'root' is the xml string? Or a DOM thing? (I am new to DOM/SAX)
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
The tutorial(understanding DOM) is at DOM tutorial,you can good intro to DOM there.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

That tutorial was very helpful.
But the print out is giving me [<the doc root>: null] which isn't even ugly.
A note on one of the pages says: "If the application does not print out the structure of the root element, check the CLASSPATH. The JAXP jar files must appear first if other XML implementations are also present. If you are using Java 2 SDK version 1.4, the output may look "pretty printed"."
I am not running 1.4, do you know what they mean by JAXP?
My code:
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Related thread
I tried lots of different solutions, not all of them I am sure, but I ended up writing my own. It is a basic state engine, no tree or anything like that. It handles attributes and subscripts.

[ October 08, 2002: Message edited by: William Barnes ]
[ October 08, 2002: Message edited by: William Barnes ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pretty printing XML